diff options
author | George Roman <george.roman.99@gmail.com> | 2018-05-13 13:57:31 +0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-05-17 18:30:29 -0300 |
commit | 42b85be332ebaabdbc7f457c484aeedd361d0528 (patch) | |
tree | 986d5afd3f2eb73c0e7143317dcbf61be1b582be | |
parent | 7cc46a5013a94b56ed50f5485cb7326c0bf5363c (diff) | |
download | luarocks-42b85be332ebaabdbc7f457c484aeedd361d0528.tar.gz luarocks-42b85be332ebaabdbc7f457c484aeedd361d0528.tar.bz2 luarocks-42b85be332ebaabdbc7f457c484aeedd361d0528.zip |
Replace fs.chmod with fs.set_permissions
-rw-r--r-- | src/luarocks/admin/cmd/add.lua | 4 | ||||
-rw-r--r-- | src/luarocks/build.lua | 14 | ||||
-rw-r--r-- | src/luarocks/build/builtin.lua | 2 | ||||
-rw-r--r-- | src/luarocks/cmd/unpack.lua | 2 | ||||
-rw-r--r-- | src/luarocks/core/cfg.lua | 3 | ||||
-rw-r--r-- | src/luarocks/download.lua | 2 | ||||
-rw-r--r-- | src/luarocks/fs/lua.lua | 30 | ||||
-rw-r--r-- | src/luarocks/fs/unix.lua | 4 | ||||
-rw-r--r-- | src/luarocks/fs/unix/tools.lua | 72 | ||||
-rw-r--r-- | src/luarocks/fs/win32.lua | 4 | ||||
-rw-r--r-- | src/luarocks/fs/win32/tools.lua | 53 | ||||
-rw-r--r-- | src/luarocks/pack.lua | 6 | ||||
-rw-r--r-- | src/luarocks/repos.lua | 4 | ||||
-rw-r--r-- | src/luarocks/tools/tar.lua | 1 | ||||
-rw-r--r-- | src/luarocks/upload/api.lua | 3 |
15 files changed, 161 insertions, 43 deletions
diff --git a/src/luarocks/admin/cmd/add.lua b/src/luarocks/admin/cmd/add.lua index 5cfec980..19990b3c 100644 --- a/src/luarocks/admin/cmd/add.lua +++ b/src/luarocks/admin/cmd/add.lua | |||
@@ -62,7 +62,7 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server, do | |||
62 | if fs.exists(rockfile) then | 62 | if fs.exists(rockfile) then |
63 | util.printout("Copying file "..rockfile.." to "..local_cache.."...") | 63 | util.printout("Copying file "..rockfile.." to "..local_cache.."...") |
64 | local absolute = fs.absolute_name(rockfile) | 64 | local absolute = fs.absolute_name(rockfile) |
65 | fs.copy(absolute, local_cache, cfg.perm_read) | 65 | fs.copy(absolute, local_cache, "read") |
66 | table.insert(files, dir.base_name(absolute)) | 66 | table.insert(files, dir.base_name(absolute)) |
67 | else | 67 | else |
68 | util.printerr("File "..rockfile.." not found") | 68 | util.printerr("File "..rockfile.." not found") |
@@ -83,7 +83,7 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server, do | |||
83 | if fs.exists("index.html") then | 83 | if fs.exists("index.html") then |
84 | do_index = true | 84 | do_index = true |
85 | end | 85 | end |
86 | 86 | ||
87 | if do_index then | 87 | if do_index then |
88 | util.printout("Updating index.html...") | 88 | util.printout("Updating index.html...") |
89 | index.make_index(local_cache) | 89 | index.make_index(local_cache) |
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index dfc54cb8..fe004fb5 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
@@ -24,7 +24,7 @@ local writer = require("luarocks.manif.writer") | |||
24 | -- @param location string: The base directory files should be copied to. | 24 | -- @param location string: The base directory files should be copied to. |
25 | -- @param is_module_path boolean: True if string keys in files should be | 25 | -- @param is_module_path boolean: True if string keys in files should be |
26 | -- interpreted as dotted module paths. | 26 | -- interpreted as dotted module paths. |
27 | -- @param perms string: Permissions of the newly created files installed. | 27 | -- @param perms string ("read" or "exec"): Permissions of the newly created files installed. |
28 | -- Directories are always created with the default permissions. | 28 | -- Directories are always created with the default permissions. |
29 | -- @return boolean or (nil, string): True if succeeded or | 29 | -- @return boolean or (nil, string): True if succeeded or |
30 | -- nil and an error message. | 30 | -- nil and an error message. |
@@ -113,7 +113,7 @@ local function install_default_docs(name, version) | |||
113 | fs.make_dir(dest) | 113 | fs.make_dir(dest) |
114 | has_dir = true | 114 | has_dir = true |
115 | end | 115 | end |
116 | fs.copy(file, dest, cfg.perm_read) | 116 | fs.copy(file, dest, "read") |
117 | break | 117 | break |
118 | end | 118 | end |
119 | end | 119 | end |
@@ -229,10 +229,10 @@ function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_m | |||
229 | end | 229 | end |
230 | 230 | ||
231 | local dirs = { | 231 | local dirs = { |
232 | lua = { name = path.lua_dir(name, version), is_module_path = true, perms = cfg.perm_read }, | 232 | lua = { name = path.lua_dir(name, version), is_module_path = true, perms = "read" }, |
233 | lib = { name = path.lib_dir(name, version), is_module_path = true, perms = cfg.perm_exec }, | 233 | lib = { name = path.lib_dir(name, version), is_module_path = true, perms = "exec" }, |
234 | conf = { name = path.conf_dir(name, version), is_module_path = false, perms = cfg.perm_read }, | 234 | conf = { name = path.conf_dir(name, version), is_module_path = false, perms = "read" }, |
235 | bin = { name = path.bin_dir(name, version), is_module_path = false, perms = cfg.perm_exec }, | 235 | bin = { name = path.bin_dir(name, version), is_module_path = false, perms = "exec" }, |
236 | } | 236 | } |
237 | 237 | ||
238 | for _, d in pairs(dirs) do | 238 | for _, d in pairs(dirs) do |
@@ -322,7 +322,7 @@ function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_m | |||
322 | 322 | ||
323 | fs.pop_dir() | 323 | fs.pop_dir() |
324 | 324 | ||
325 | fs.copy(rockspec.local_filename, path.rockspec_file(name, version), cfg.perm_read) | 325 | fs.copy(rockspec.local_filename, path.rockspec_file(name, version), "read") |
326 | if need_to_fetch then | 326 | if need_to_fetch then |
327 | fs.pop_dir() | 327 | fs.pop_dir() |
328 | end | 328 | end |
diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index 294ff52b..68fb75ed 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua | |||
@@ -290,7 +290,7 @@ function builtin.run(rockspec) | |||
290 | ]] | 290 | ]] |
291 | end | 291 | end |
292 | end | 292 | end |
293 | for _, mods in ipairs({{ tbl = lua_modules, perms = cfg.perm_read }, { tbl = lib_modules, perms = cfg.perm_exec }}) do | 293 | for _, mods in ipairs({{ tbl = lua_modules, perms = "read" }, { tbl = lib_modules, perms = "exec" }}) do |
294 | for name, dest in pairs(mods.tbl) do | 294 | for name, dest in pairs(mods.tbl) do |
295 | fs.make_dir(dir.dir_name(dest)) | 295 | fs.make_dir(dir.dir_name(dest)) |
296 | ok, err = fs.copy(name, dest, mods.perms) | 296 | ok, err = fs.copy(name, dest, mods.perms) |
diff --git a/src/luarocks/cmd/unpack.lua b/src/luarocks/cmd/unpack.lua index f4232266..3e512d5d 100644 --- a/src/luarocks/cmd/unpack.lua +++ b/src/luarocks/cmd/unpack.lua | |||
@@ -126,7 +126,7 @@ local function run_unpacker(file, namespace, force) | |||
126 | end | 126 | end |
127 | if kind == "src" or kind == "rockspec" then | 127 | if kind == "src" or kind == "rockspec" then |
128 | if rockspec.source.dir ~= "." then | 128 | if rockspec.source.dir ~= "." then |
129 | local ok = fs.copy(rockspec.local_filename, rockspec.source.dir, cfg.perm_read) | 129 | local ok = fs.copy(rockspec.local_filename, rockspec.source.dir, "read") |
130 | if not ok then | 130 | if not ok then |
131 | return nil, "Failed copying unpacked rockspec into unpacked source directory." | 131 | return nil, "Failed copying unpacked rockspec into unpacked source directory." |
132 | end | 132 | end |
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index 3326375f..f036aa44 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua | |||
@@ -327,8 +327,6 @@ local defaults = { | |||
327 | hooks_enabled = true, | 327 | hooks_enabled = true, |
328 | deps_mode = "one", | 328 | deps_mode = "one", |
329 | check_certificates = false, | 329 | check_certificates = false, |
330 | perm_read = "0644", | ||
331 | perm_exec = "0755", | ||
332 | 330 | ||
333 | lua_modules_path = "/share/lua/"..cfg.lua_version, | 331 | lua_modules_path = "/share/lua/"..cfg.lua_version, |
334 | lib_modules_path = "/lib/lua/"..cfg.lua_version, | 332 | lib_modules_path = "/lib/lua/"..cfg.lua_version, |
@@ -388,6 +386,7 @@ local defaults = { | |||
388 | FIND = "find", | 386 | FIND = "find", |
389 | TEST = "test", | 387 | TEST = "test", |
390 | CHMOD = "chmod", | 388 | CHMOD = "chmod", |
389 | ICACLS = "icacls", | ||
391 | MKTEMP = "mktemp", | 390 | MKTEMP = "mktemp", |
392 | 391 | ||
393 | ZIP = "zip", | 392 | ZIP = "zip", |
diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua index 77564b52..ac401f33 100644 --- a/src/luarocks/download.lua +++ b/src/luarocks/download.lua | |||
@@ -11,7 +11,7 @@ local cfg = require("luarocks.core.cfg") | |||
11 | local function get_file(filename) | 11 | local function get_file(filename) |
12 | local protocol, pathname = dir.split_url(filename) | 12 | local protocol, pathname = dir.split_url(filename) |
13 | if protocol == "file" then | 13 | if protocol == "file" then |
14 | local ok, err = fs.copy(pathname, fs.current_dir(), cfg.perm_read) | 14 | local ok, err = fs.copy(pathname, fs.current_dir(), "read") |
15 | if ok then | 15 | if ok then |
16 | return pathname | 16 | return pathname |
17 | else | 17 | else |
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index dfb6de41..69c75cec 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
@@ -241,7 +241,7 @@ function fs_lua.make_dir(directory) | |||
241 | if not ok then | 241 | if not ok then |
242 | return false, err | 242 | return false, err |
243 | end | 243 | end |
244 | ok, err = fs.chmod(path, cfg.perm_exec) | 244 | ok, err = fs.set_permissions(path, "exec", "user") |
245 | if not ok then | 245 | if not ok then |
246 | return false, err | 246 | return false, err |
247 | end | 247 | end |
@@ -278,8 +278,8 @@ end | |||
278 | --- Copy a file. | 278 | --- Copy a file. |
279 | -- @param src string: Pathname of source | 279 | -- @param src string: Pathname of source |
280 | -- @param dest string: Pathname of destination | 280 | -- @param dest string: Pathname of destination |
281 | -- @param perms string or nil: Permissions for destination file, | 281 | -- @param perms string ("read" or "exec") or nil: Permissions for destination |
282 | -- or nil to use the source filename permissions | 282 | -- file or nil to use the source file permissions |
283 | -- @return boolean or (boolean, string): true on success, false on failure, | 283 | -- @return boolean or (boolean, string): true on success, false on failure, |
284 | -- plus an error message. | 284 | -- plus an error message. |
285 | function fs_lua.copy(src, dest, perms) | 285 | function fs_lua.copy(src, dest, perms) |
@@ -290,7 +290,6 @@ function fs_lua.copy(src, dest, perms) | |||
290 | if destmode == "directory" then | 290 | if destmode == "directory" then |
291 | dest = dir.path(dest, dir.base_name(src)) | 291 | dest = dir.path(dest, dir.base_name(src)) |
292 | end | 292 | end |
293 | if not perms then perms = fs.attributes(src, "permissions") end | ||
294 | local src_h, err = io.open(src, "rb") | 293 | local src_h, err = io.open(src, "rb") |
295 | if not src_h then return nil, err end | 294 | if not src_h then return nil, err end |
296 | local dest_h, err = io.open(dest, "w+b") | 295 | local dest_h, err = io.open(dest, "w+b") |
@@ -302,15 +301,26 @@ function fs_lua.copy(src, dest, perms) | |||
302 | end | 301 | end |
303 | src_h:close() | 302 | src_h:close() |
304 | dest_h:close() | 303 | dest_h:close() |
305 | fs.chmod(dest, perms) | 304 | |
306 | return true | 305 | local fullattrs |
306 | if not perms then | ||
307 | fullattrs = lfs.attributes(src, "permissions") | ||
308 | end | ||
309 | if fullattrs and posix_ok then | ||
310 | return posix.chmod(dest, fullattrs) | ||
311 | else | ||
312 | if not perms then | ||
313 | perms = fullattrs:match("x") and "exec" or "read" | ||
314 | end | ||
315 | return fs.set_permissions(dest, perms, "all") | ||
316 | end | ||
307 | end | 317 | end |
308 | 318 | ||
309 | --- Implementation function for recursive copy of directory contents. | 319 | --- Implementation function for recursive copy of directory contents. |
310 | -- Assumes paths are normalized. | 320 | -- Assumes paths are normalized. |
311 | -- @param src string: Pathname of source | 321 | -- @param src string: Pathname of source |
312 | -- @param dest string: Pathname of destination | 322 | -- @param dest string: Pathname of destination |
313 | -- @param perms string or nil: Optional permissions. | 323 | -- @param perms string ("read" or "exec") or nil: Optional permissions. |
314 | -- If not given, permissions of the source are copied over to the destination. | 324 | -- If not given, permissions of the source are copied over to the destination. |
315 | -- @return boolean or (boolean, string): true on success, false on failure | 325 | -- @return boolean or (boolean, string): true on success, false on failure |
316 | local function recursive_copy(src, dest, perms) | 326 | local function recursive_copy(src, dest, perms) |
@@ -339,7 +349,7 @@ end | |||
339 | --- Recursively copy the contents of a directory. | 349 | --- Recursively copy the contents of a directory. |
340 | -- @param src string: Pathname of source | 350 | -- @param src string: Pathname of source |
341 | -- @param dest string: Pathname of destination | 351 | -- @param dest string: Pathname of destination |
342 | -- @param perms string or nil: Optional permissions. | 352 | -- @param perms string ("read" or "exec") or nil: Optional permissions. |
343 | -- @return boolean or (boolean, string): true on success, false on failure, | 353 | -- @return boolean or (boolean, string): true on success, false on failure, |
344 | -- plus an error message. | 354 | -- plus an error message. |
345 | function fs_lua.copy_contents(src, dest, perms) | 355 | function fs_lua.copy_contents(src, dest, perms) |
@@ -833,8 +843,8 @@ end | |||
833 | --- Move a file. | 843 | --- Move a file. |
834 | -- @param src string: Pathname of source | 844 | -- @param src string: Pathname of source |
835 | -- @param dest string: Pathname of destination | 845 | -- @param dest string: Pathname of destination |
836 | -- @param perms string or nil: Permissions for destination file, | 846 | -- @param perms string ("read" or "exec") or nil: Permissions for destination |
837 | -- or nil to use the source filename permissions. | 847 | -- file or nil to use the source file permissions. |
838 | -- @return boolean or (boolean, string): true on success, false on failure, | 848 | -- @return boolean or (boolean, string): true on success, false on failure, |
839 | -- plus an error message. | 849 | -- plus an error message. |
840 | function fs_lua.move(src, dest, perms) | 850 | function fs_lua.move(src, dest, perms) |
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index c99e1566..b64a4a38 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua | |||
@@ -81,7 +81,7 @@ function unix.wrap_script(file, dest, name, version) | |||
81 | local addctx = "local k,l,_=pcall(require,"..util.LQ("luarocks.loader")..") _=k and l.add_context("..util.LQ(name)..","..util.LQ(version)..")" | 81 | local addctx = "local k,l,_=pcall(require,"..util.LQ("luarocks.loader")..") _=k and l.add_context("..util.LQ(name)..","..util.LQ(version)..")" |
82 | wrapper:write('exec '..fs.Q(lua)..' -e '..fs.Q(ppaths)..' -e '..fs.Q(addctx)..' '..fs.Q(file)..' "$@"\n') | 82 | wrapper:write('exec '..fs.Q(lua)..' -e '..fs.Q(ppaths)..' -e '..fs.Q(addctx)..' '..fs.Q(file)..' "$@"\n') |
83 | wrapper:close() | 83 | wrapper:close() |
84 | if fs.chmod(wrapname, cfg.perm_exec) then | 84 | if fs.set_permissions(wrapname, "exec", "user") then |
85 | return true | 85 | return true |
86 | else | 86 | else |
87 | return nil, "Could not make "..wrapname.." executable." | 87 | return nil, "Could not make "..wrapname.." executable." |
@@ -111,7 +111,7 @@ function unix.is_actual_binary(filename) | |||
111 | end | 111 | end |
112 | 112 | ||
113 | function unix.copy_binary(filename, dest) | 113 | function unix.copy_binary(filename, dest) |
114 | return fs.copy(filename, dest, cfg.perm_exec) | 114 | return fs.copy(filename, dest, "exec") |
115 | end | 115 | end |
116 | 116 | ||
117 | --- Move a file on top of the other. | 117 | --- Move a file on top of the other. |
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index be5ba7a7..06098399 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
@@ -51,7 +51,8 @@ end | |||
51 | --- Copy a file. | 51 | --- Copy a file. |
52 | -- @param src string: Pathname of source | 52 | -- @param src string: Pathname of source |
53 | -- @param dest string: Pathname of destination | 53 | -- @param dest string: Pathname of destination |
54 | -- @param perm string or nil: Permissions for destination file, | 54 | -- @param perm string ("read" or "exec") or nil: Permissions for destination |
55 | -- file or nil to use the source permissions | ||
55 | -- @return boolean or (boolean, string): true on success, false on failure, | 56 | -- @return boolean or (boolean, string): true on success, false on failure, |
56 | -- plus an error message. | 57 | -- plus an error message. |
57 | function tools.copy(src, dest, perm) | 58 | function tools.copy(src, dest, perm) |
@@ -61,7 +62,7 @@ function tools.copy(src, dest, perm) | |||
61 | if fs.is_dir(dest) then | 62 | if fs.is_dir(dest) then |
62 | dest = dir.path(dest, dir.base_name(src)) | 63 | dest = dir.path(dest, dir.base_name(src)) |
63 | end | 64 | end |
64 | if fs.chmod(dest, perm) then | 65 | if fs.set_permissions(dest, perm, "all") then |
65 | return true | 66 | return true |
66 | else | 67 | else |
67 | return false, "Failed setting permissions of "..dest | 68 | return false, "Failed setting permissions of "..dest |
@@ -159,12 +160,71 @@ function tools.is_file(file) | |||
159 | return fs.execute(vars.TEST, "-f", file) | 160 | return fs.execute(vars.TEST, "-f", file) |
160 | end | 161 | end |
161 | 162 | ||
162 | function tools.chmod(pathname, mode) | 163 | --- Moderate the given permissions based on the local umask |
163 | if mode then | 164 | -- @param perms string: permissions to moderate |
164 | return fs.execute(vars.CHMOD, mode, pathname) | 165 | -- @return string: the moderated permissions |
166 | local function moderate_permissions(perms) | ||
167 | local octal_to_rwx = { | ||
168 | ["0"] = "---", | ||
169 | ["1"] = "--x", | ||
170 | ["2"] = "-w-", | ||
171 | ["3"] = "-wx", | ||
172 | ["4"] = "r--", | ||
173 | ["5"] = "r-x", | ||
174 | ["6"] = "rw-", | ||
175 | ["7"] = "rwx", | ||
176 | } | ||
177 | local rwx_to_octal = {} | ||
178 | for octal, rwx in pairs(octal_to_rwx) do | ||
179 | rwx_to_octal[rwx] = octal | ||
180 | end | ||
181 | |||
182 | local fd = assert(io.popen("umask")) | ||
183 | local umask = assert(fd:read("*a")) | ||
184 | umask = umask:gsub("\n", "") | ||
185 | umask = umask:sub(2, 4) | ||
186 | |||
187 | local moderated_perms = "" | ||
188 | for i = 1, 3 do | ||
189 | local p_rwx = octal_to_rwx[perms:sub(i, i)] | ||
190 | local u_rwx = octal_to_rwx[umask:sub(i, i)] | ||
191 | local new_perm = "" | ||
192 | for j = 1, 3 do | ||
193 | local p_val = p_rwx:sub(j, j) | ||
194 | local u_val = u_rwx:sub(j, j) | ||
195 | if p_val == u_val then | ||
196 | new_perm = new_perm .. "-" | ||
197 | else | ||
198 | new_perm = new_perm .. p_val | ||
199 | end | ||
200 | end | ||
201 | moderated_perms = moderated_perms .. rwx_to_octal[new_perm] | ||
202 | end | ||
203 | return moderated_perms | ||
204 | end | ||
205 | |||
206 | --- Set permissions for file or directory | ||
207 | -- @param filename string: filename whose permissions are to be modified | ||
208 | -- @param mode string ("read" or "exec"): permissions to set | ||
209 | -- @param scope string ("user" or "all"): the user(s) to whom the permission applies | ||
210 | -- @return boolean or (boolean, string): true on success, false on failure, | ||
211 | -- plus an error message | ||
212 | function tools.set_permissions(filename, mode, scope) | ||
213 | assert(filename and mode and scope) | ||
214 | |||
215 | local perms | ||
216 | if mode == "read" and scope == "user" then | ||
217 | perms = moderate_permissions("600") | ||
218 | elseif mode == "exec" and scope == "user" then | ||
219 | perms = moderate_permissions("700") | ||
220 | elseif mode == "read" and scope == "all" then | ||
221 | perms = moderate_permissions("644") | ||
222 | elseif mode == "exec" and scope == "all" then | ||
223 | perms = moderate_permissions("755") | ||
165 | else | 224 | else |
166 | return false | 225 | return false, "Invalid permission " .. mode .. " for " .. scope |
167 | end | 226 | end |
227 | return fs.execute(vars.CHMOD, perms, filename) | ||
168 | end | 228 | end |
169 | 229 | ||
170 | --- Unpack an archive. | 230 | --- Unpack an archive. |
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index a915deb6..c2331cad 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua | |||
@@ -187,10 +187,6 @@ function win32.copy_binary(filename, dest) | |||
187 | return true | 187 | return true |
188 | end | 188 | end |
189 | 189 | ||
190 | function win32.chmod(filename, mode) | ||
191 | return true | ||
192 | end | ||
193 | |||
194 | function win32.attributes(filename, attrtype) | 190 | function win32.attributes(filename, attrtype) |
195 | if attrtype == "permissions" then | 191 | if attrtype == "permissions" then |
196 | return "" -- FIXME | 192 | return "" -- FIXME |
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index b59d9391..d0a7d8b2 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua | |||
@@ -159,6 +159,59 @@ function tools.is_file(file) | |||
159 | return fs.execute(fs.Q(vars.TEST).." -f", file) | 159 | return fs.execute(fs.Q(vars.TEST).." -f", file) |
160 | end | 160 | end |
161 | 161 | ||
162 | --- Helper function for fs.set_permissions | ||
163 | -- @return table: an array of all system users | ||
164 | local function get_system_users() | ||
165 | result = {} | ||
166 | local fd = assert(io.popen("wmic UserAccount get name")) | ||
167 | for user in fd:lines() do | ||
168 | user = user:gsub("%s+$", "") | ||
169 | if user ~= "" and user ~= "Name" and user ~= "Administrator" then | ||
170 | table.insert(result, user) | ||
171 | end | ||
172 | end | ||
173 | return result | ||
174 | end | ||
175 | |||
176 | --- Set permissions for file or directory | ||
177 | -- @param filename string: filename whose permissions are to be modified | ||
178 | -- @param mode string ("read" or "exec"): permission to set | ||
179 | -- @param scope string ("user" or "all"): the user(s) to whom the permission applies | ||
180 | -- @return boolean or (boolean, string): true on success, false on failure, | ||
181 | -- plus an error message | ||
182 | function tools.set_permissions(filename, mode, scope) | ||
183 | assert(filename and mode and scope) | ||
184 | |||
185 | local who, what | ||
186 | if scope == "user" then | ||
187 | who = os.getenv("USERNAME") | ||
188 | elseif scope == "all" then | ||
189 | who = "Everyone" | ||
190 | end | ||
191 | if mode == "read" then | ||
192 | what = "(RD)" | ||
193 | elseif mode == "exec" then | ||
194 | what = "(X)" | ||
195 | end | ||
196 | if not who or not what then | ||
197 | return false, "Invalid permission " .. mode .. " for " .. scope | ||
198 | end | ||
199 | |||
200 | if scope == "user" then | ||
201 | for _, user in pairs(get_system_users()) do | ||
202 | if user ~= who then | ||
203 | local ok = fs.execute(fs.Q(vars.ICACLS) .. " " .. fs.Q(filename) .. " /deny " .. fs.Q(user) .. ":" .. fs.Q(what)) | ||
204 | if not ok then | ||
205 | return false, "Failed setting permission " .. mode .. " for " .. scope | ||
206 | end | ||
207 | end | ||
208 | end | ||
209 | end | ||
210 | |||
211 | return fs.execute(fs.Q(vars.ICACLS) .. " " .. fs.Q(filename) .. " /grant " .. fs.Q(who) .. ":" .. fs.Q(what)) | ||
212 | end | ||
213 | |||
214 | |||
162 | --- Strip the last extension of a filename. | 215 | --- Strip the last extension of a filename. |
163 | -- Example: "foo.tar.gz" becomes "foo.tar". | 216 | -- Example: "foo.tar.gz" becomes "foo.tar". |
164 | -- If filename has no dots, returns it unchanged. | 217 | -- If filename has no dots, returns it unchanged. |
diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua index e0e94283..6423de2c 100644 --- a/src/luarocks/pack.lua +++ b/src/luarocks/pack.lua | |||
@@ -42,7 +42,7 @@ function pack.pack_source_rock(rockspec_file) | |||
42 | if not ok then return nil, err end | 42 | if not ok then return nil, err end |
43 | 43 | ||
44 | fs.delete(rock_file) | 44 | fs.delete(rock_file) |
45 | fs.copy(rockspec_file, source_dir, cfg.perm_read) | 45 | fs.copy(rockspec_file, source_dir, "read") |
46 | if not fs.zip(rock_file, dir.base_name(rockspec_file), dir.base_name(source_file)) then | 46 | if not fs.zip(rock_file, dir.base_name(rockspec_file), dir.base_name(source_file)) then |
47 | return nil, "Failed packing "..rock_file | 47 | return nil, "Failed packing "..rock_file |
48 | end | 48 | end |
@@ -101,12 +101,12 @@ function pack.pack_installed_rock(query, tree) | |||
101 | 101 | ||
102 | local is_binary = false | 102 | local is_binary = false |
103 | if rock_manifest.lib then | 103 | if rock_manifest.lib then |
104 | local ok, err = copy_back_files(name, version, rock_manifest.lib, path.deploy_lib_dir(root), dir.path(temp_dir, "lib"), cfg.perm_exec) | 104 | local ok, err = copy_back_files(name, version, rock_manifest.lib, path.deploy_lib_dir(root), dir.path(temp_dir, "lib"), "exec") |
105 | if not ok then return nil, "Failed copying back files: " .. err end | 105 | if not ok then return nil, "Failed copying back files: " .. err end |
106 | is_binary = true | 106 | is_binary = true |
107 | end | 107 | end |
108 | if rock_manifest.lua then | 108 | if rock_manifest.lua then |
109 | local ok, err = copy_back_files(name, version, rock_manifest.lua, path.deploy_lua_dir(root), dir.path(temp_dir, "lua"), cfg.perm_read) | 109 | local ok, err = copy_back_files(name, version, rock_manifest.lua, path.deploy_lua_dir(root), dir.path(temp_dir, "lua"), "read") |
110 | if not ok then return nil, "Failed copying back files: " .. err end | 110 | if not ok then return nil, "Failed copying back files: " .. err end |
111 | end | 111 | end |
112 | 112 | ||
diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua index 1464db96..54610489 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.lua | |||
@@ -330,10 +330,10 @@ function repos.deploy_files(name, version, wrap_bin_scripts, deps_mode) | |||
330 | local ok, err = deploy_file_tree("bin", path.bin_dir(name, version), install_binary, cfg.wrapper_suffix) | 330 | local ok, err = deploy_file_tree("bin", path.bin_dir(name, version), install_binary, cfg.wrapper_suffix) |
331 | if not ok then return nil, err end | 331 | if not ok then return nil, err end |
332 | 332 | ||
333 | ok, err = deploy_file_tree("lua", path.lua_dir(name, version), make_mover(cfg.perm_read)) | 333 | ok, err = deploy_file_tree("lua", path.lua_dir(name, version), make_mover("read")) |
334 | if not ok then return nil, err end | 334 | if not ok then return nil, err end |
335 | 335 | ||
336 | ok, err = deploy_file_tree("lib", path.lib_dir(name, version), make_mover(cfg.perm_exec)) | 336 | ok, err = deploy_file_tree("lib", path.lib_dir(name, version), make_mover("exec")) |
337 | if not ok then return nil, err end | 337 | if not ok then return nil, err end |
338 | 338 | ||
339 | local writer = require("luarocks.manif.writer") | 339 | local writer = require("luarocks.manif.writer") |
diff --git a/src/luarocks/tools/tar.lua b/src/luarocks/tools/tar.lua index 0d3b3c19..9ff8d04a 100644 --- a/src/luarocks/tools/tar.lua +++ b/src/luarocks/tools/tar.lua | |||
@@ -133,6 +133,7 @@ function tar.untar(filename, destdir) | |||
133 | file_handle:write(file_data) | 133 | file_handle:write(file_data) |
134 | file_handle:close() | 134 | file_handle:close() |
135 | fs.set_time(pathname, header.mtime) | 135 | fs.set_time(pathname, header.mtime) |
136 | -- TODO Use fs.set_permissions | ||
136 | if fs.chmod then | 137 | if fs.chmod then |
137 | fs.chmod(pathname, header.mode) | 138 | fs.chmod(pathname, header.mode) |
138 | end | 139 | end |
diff --git a/src/luarocks/upload/api.lua b/src/luarocks/upload/api.lua index f541e896..f9244258 100644 --- a/src/luarocks/upload/api.lua +++ b/src/luarocks/upload/api.lua | |||
@@ -42,7 +42,7 @@ function Api:save_config() | |||
42 | return nil, err | 42 | return nil, err |
43 | end | 43 | end |
44 | persist.save_from_table(upload_conf, self.config) | 44 | persist.save_from_table(upload_conf, self.config) |
45 | fs.chmod(upload_conf, "0600") | 45 | fs.set_permissions(upload_conf, "read", "user") |
46 | end | 46 | end |
47 | 47 | ||
48 | function Api:check_version() | 48 | function Api:check_version() |
@@ -286,4 +286,3 @@ function api.new(flags) | |||
286 | end | 286 | end |
287 | 287 | ||
288 | return api | 288 | return api |
289 | |||