aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2010-09-09 16:03:13 -0300
committerHisham Muhammad <hisham@gobolinux.org>2010-09-09 16:03:13 -0300
commit569ab48390725c2d87f9a89cdeb47bae3fc2cd46 (patch)
treec475a140fc085ff0714f7e9f032d7a4230a31a44
parentb6cfc996eb570cdcab1ca4d4c3e80c851aef7d1e (diff)
downloadluarocks-569ab48390725c2d87f9a89cdeb47bae3fc2cd46.tar.gz
luarocks-569ab48390725c2d87f9a89cdeb47bae3fc2cd46.tar.bz2
luarocks-569ab48390725c2d87f9a89cdeb47bae3fc2cd46.zip
Preserve permissions when copying files
-rw-r--r--src/luarocks/cfg.lua2
-rw-r--r--src/luarocks/fs/lua.lua6
-rw-r--r--src/luarocks/fs/unix.lua1
-rw-r--r--src/luarocks/fs/unix/tools.lua9
-rw-r--r--src/luarocks/fs/win32.lua8
5 files changed, 25 insertions, 1 deletions
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index 67cd17b7..45c73bf6 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -63,9 +63,11 @@ end
63if system == "FreeBSD" then 63if system == "FreeBSD" then
64 detected.unix = true 64 detected.unix = true
65 detected.freebsd = true 65 detected.freebsd = true
66 detected.bsd = true
66elseif system == "Darwin" then 67elseif system == "Darwin" then
67 detected.unix = true 68 detected.unix = true
68 detected.macosx = true 69 detected.macosx = true
70 detected.bsd = true
69elseif system == "Linux" then 71elseif system == "Linux" then
70 detected.unix = true 72 detected.unix = true
71 detected.linux = true 73 detected.linux = true
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index cd0a31e0..70df65be 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -230,6 +230,7 @@ function copy(src, dest)
230 if destmode == "directory" then 230 if destmode == "directory" then
231 dest = dir.path(dest, dir.base_name(src)) 231 dest = dir.path(dest, dir.base_name(src))
232 end 232 end
233 local perms = fs.get_permissions(src)
233 local src_h, err = io.open(src, "rb") 234 local src_h, err = io.open(src, "rb")
234 if not src_h then return nil, err end 235 if not src_h then return nil, err end
235 local dest_h, err = io.open(dest, "wb+") 236 local dest_h, err = io.open(dest, "wb+")
@@ -241,6 +242,7 @@ function copy(src, dest)
241 end 242 end
242 src_h:close() 243 src_h:close()
243 dest_h:close() 244 dest_h:close()
245 fs.chmod(dest, perms)
244 return true 246 return true
245end 247end
246 248
@@ -571,6 +573,10 @@ function chmod(file, mode)
571 return err == 0 573 return err == 0
572end 574end
573 575
576function get_permissions(file)
577 return posix.stat(file, "mode")
578end
579
574end 580end
575 581
576--------------------------------------------------------------------- 582---------------------------------------------------------------------
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua
index 94a3ad4e..f2290412 100644
--- a/src/luarocks/fs/unix.lua
+++ b/src/luarocks/fs/unix.lua
@@ -122,4 +122,3 @@ end
122function copy_binary(filename, dest) 122function copy_binary(filename, dest)
123 return fs.copy(filename, dest) 123 return fs.copy(filename, dest)
124end 124end
125
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index 33dbc489..2bfa7c3e 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -343,3 +343,12 @@ function unpack_archive(archive)
343 end 343 end
344 return true 344 return true
345end 345end
346
347function get_permissions(filename)
348 local ret
349 local flag = cfg.is_platform("bsd") and "-f '%A'" or "-c '%a'"
350 local pipe = io.popen("stat "..flag.." "..fs.Q(filename))
351 ret = pipe:read("*l")
352 pipe:close()
353 return ret
354end
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua
index d87ad90d..44740850 100644
--- a/src/luarocks/fs/win32.lua
+++ b/src/luarocks/fs/win32.lua
@@ -95,3 +95,11 @@ function copy_binary(filename, dest)
95 end 95 end
96 return true 96 return true
97end 97end
98
99function chmod(filename, mode)
100 return true
101end
102
103function get_permissions(filename)
104 return ""
105end