aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2024-05-14 14:59:56 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-05-14 15:48:56 -0300
commite930ef7868056f1eb666dc3179ef7f7ce094d805 (patch)
treee8c454b33d89b030f0709a39a85e24d2c95ad04e
parent81c23bc4cb518b2892ed1ffd089e610a45013692 (diff)
downloadluarocks-honor-umask.tar.gz
luarocks-honor-umask.tar.bz2
luarocks-honor-umask.zip
fs(unix): honor umask correctlyhonor-umask
-rw-r--r--src/luarocks/fs/lua.lua14
-rw-r--r--src/luarocks/fs/unix.lua18
-rw-r--r--src/luarocks/fs/unix/tools.lua15
3 files changed, 24 insertions, 23 deletions
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index 6e8c4670..4016ddcd 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -1070,17 +1070,9 @@ do
1070end 1070end
1071 1071
1072function fs_lua.set_permissions(filename, mode, scope) 1072function fs_lua.set_permissions(filename, mode, scope)
1073 local perms 1073 local perms, err = fs._unix_mode_scope_to_perms(mode, scope)
1074 if mode == "read" and scope == "user" then 1074 if err then
1075 perms = fs._unix_moderate_permissions("600") 1075 return false, err
1076 elseif mode == "exec" and scope == "user" then
1077 perms = fs._unix_moderate_permissions("700")
1078 elseif mode == "read" and scope == "all" then
1079 perms = fs._unix_moderate_permissions("644")
1080 elseif mode == "exec" and scope == "all" then
1081 perms = fs._unix_moderate_permissions("755")
1082 else
1083 return false, "Invalid permission " .. mode .. " for " .. scope
1084 end 1076 end
1085 1077
1086 -- LuaPosix (as of 5.1.15) does not support octal notation... 1078 -- LuaPosix (as of 5.1.15) does not support octal notation...
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua
index f5f3b349..41a9ba8b 100644
--- a/src/luarocks/fs/unix.lua
+++ b/src/luarocks/fs/unix.lua
@@ -197,7 +197,7 @@ end
197--- Moderate the given permissions based on the local umask 197--- Moderate the given permissions based on the local umask
198-- @param perms string: permissions to moderate 198-- @param perms string: permissions to moderate
199-- @return string: the moderated permissions 199-- @return string: the moderated permissions
200function unix._unix_moderate_permissions(perms) 200local function apply_umask(perms)
201 local umask = fs._unix_umask() 201 local umask = fs._unix_umask()
202 202
203 local moderated_perms = "" 203 local moderated_perms = ""
@@ -219,6 +219,22 @@ function unix._unix_moderate_permissions(perms)
219 return moderated_perms 219 return moderated_perms
220end 220end
221 221
222function unix._unix_mode_scope_to_perms(mode, scope)
223 local perms
224 if mode == "read" and scope == "user" then
225 perms = apply_umask("600")
226 elseif mode == "exec" and scope == "user" then
227 perms = apply_umask("700")
228 elseif mode == "read" and scope == "all" then
229 perms = apply_umask("666")
230 elseif mode == "exec" and scope == "all" then
231 perms = apply_umask("777")
232 else
233 return false, "Invalid permission " .. mode .. " for " .. scope
234 end
235 return perms
236end
237
222function unix.system_cache_dir() 238function unix.system_cache_dir()
223 if fs.is_dir("/var/cache") then 239 if fs.is_dir("/var/cache") then
224 return "/var/cache" 240 return "/var/cache"
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index 16b31335..d7334733 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -221,18 +221,11 @@ end
221function tools.set_permissions(filename, mode, scope) 221function tools.set_permissions(filename, mode, scope)
222 assert(filename and mode and scope) 222 assert(filename and mode and scope)
223 223
224 local perms 224 local perms, err = fs._unix_mode_scope_to_perms(mode, scope)
225 if mode == "read" and scope == "user" then 225 if err then
226 perms = fs._unix_moderate_permissions("600") 226 return false, err
227 elseif mode == "exec" and scope == "user" then
228 perms = fs._unix_moderate_permissions("700")
229 elseif mode == "read" and scope == "all" then
230 perms = fs._unix_moderate_permissions("644")
231 elseif mode == "exec" and scope == "all" then
232 perms = fs._unix_moderate_permissions("755")
233 else
234 return false, "Invalid permission " .. mode .. " for " .. scope
235 end 227 end
228
236 return fs.execute(vars.CHMOD, perms, filename) 229 return fs.execute(vars.CHMOD, perms, filename)
237end 230end
238 231