From 842d7342eb12d133fa85514d801983095300e76c Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 25 Jul 2018 19:22:16 -0300 Subject: fs: fix rwx_to_number, add negated mask mode Fixes #856. --- src/luarocks/fs/lua.lua | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 74d8f12f..13b46e19 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -871,6 +871,18 @@ end -- POSIX functions --------------------------------------------------------------------- +function fs_lua._unix_rwx_to_number(rwx, neg) + local num = 0 + neg = neg or false + for i = 1, 9 do + local c = rwx:sub(10 - i, 10 - i) == "-" + if neg == c then + num = num + 2^(i-1) + end + end + return math.floor(num) +end + if posix_ok then local octal_to_rwx = { @@ -884,16 +896,6 @@ local octal_to_rwx = { ["7"] = "rwx", } -function fs_lua._unix_rwx_to_number(rwx) - local num = 0 - for i = 1, 9 do - if rwx:sub(10 - i, 10 - i) == "-" then - num = num + 2^i - end - end - return num -end - do local umask_cache function fs_lua._unix_umask() @@ -902,7 +904,7 @@ do end -- LuaPosix (as of 34.0.4) only returns the umask as rwx local rwx = posix.umask() - local num = fs_lua._unix_rwx_to_number(rwx) + local num = fs_lua._unix_rwx_to_number(rwx, true) umask_cache = ("%03o"):format(num) return umask_cache end -- cgit v1.2.3-55-g6feb