From 9534e4c10af1b0a4f605b616b9d1ba8399d36ce0 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 24 Oct 2011 01:05:13 -0200 Subject: force executable permissions when copying entries into bin/ --- src/luarocks/fs/lua.lua | 6 ++++-- src/luarocks/fs/unix.lua | 2 +- src/luarocks/fs/unix/tools.lua | 13 ++++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 1a7e4eff..a286ca50 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -231,9 +231,11 @@ end --- Copy a file. -- @param src string: Pathname of source -- @param dest string: Pathname of destination +-- @param perms string or nil: Permissions for destination file, +-- or nil to use the source filename permissions -- @return boolean or (boolean, string): true on success, false on failure, -- plus an error message. -function copy(src, dest) +function copy(src, dest, perms) assert(src and dest) src = normalize(src) dest = normalize(dest) @@ -241,7 +243,7 @@ function copy(src, dest) if destmode == "directory" then dest = dir.path(dest, dir.base_name(src)) end - local perms = fs.get_permissions(src) + if not perms then perms = fs.get_permissions(src) end local src_h, err = io.open(src, "rb") if not src_h then return nil, err end local dest_h, err = io.open(dest, "wb+") diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index 0930cadb..844a6fb0 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua @@ -126,5 +126,5 @@ function is_actual_binary(filename) end function copy_binary(filename, dest) - return fs.copy(filename, dest) + return fs.copy(filename, dest, "0755") end diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index d1722f4b..73f01518 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua @@ -91,11 +91,22 @@ end --- Copy a file. -- @param src string: Pathname of source -- @param dest string: Pathname of destination +-- @param perms string or nil: Permissions for destination file, -- @return boolean or (boolean, string): true on success, false on failure, -- plus an error message. -function copy(src, dest) +function copy(src, dest, perm) assert(src and dest) if fs.execute(vars.CP, src, dest) then + if perm then + if fs.is_dir(dest) then + dest = dir.path(dest, dir.base_name(src)) + end + if fs.execute(vars.CHMOD, perm, dest) then + return true + else + return false, "Failed setting permissions of "..dest + end + end return true else return false, "Failed copying "..src.." to "..dest -- cgit v1.2.3-55-g6feb