aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/fs/lua.lua24
1 files changed, 13 insertions, 11 deletions
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
871-- POSIX functions 871-- POSIX functions
872--------------------------------------------------------------------- 872---------------------------------------------------------------------
873 873
874function fs_lua._unix_rwx_to_number(rwx, neg)
875 local num = 0
876 neg = neg or false
877 for i = 1, 9 do
878 local c = rwx:sub(10 - i, 10 - i) == "-"
879 if neg == c then
880 num = num + 2^(i-1)
881 end
882 end
883 return math.floor(num)
884end
885
874if posix_ok then 886if posix_ok then
875 887
876local octal_to_rwx = { 888local octal_to_rwx = {
@@ -884,16 +896,6 @@ local octal_to_rwx = {
884 ["7"] = "rwx", 896 ["7"] = "rwx",
885} 897}
886 898
887function fs_lua._unix_rwx_to_number(rwx)
888 local num = 0
889 for i = 1, 9 do
890 if rwx:sub(10 - i, 10 - i) == "-" then
891 num = num + 2^i
892 end
893 end
894 return num
895end
896
897do 899do
898 local umask_cache 900 local umask_cache
899 function fs_lua._unix_umask() 901 function fs_lua._unix_umask()
@@ -902,7 +904,7 @@ do
902 end 904 end
903 -- LuaPosix (as of 34.0.4) only returns the umask as rwx 905 -- LuaPosix (as of 34.0.4) only returns the umask as rwx
904 local rwx = posix.umask() 906 local rwx = posix.umask()
905 local num = fs_lua._unix_rwx_to_number(rwx) 907 local num = fs_lua._unix_rwx_to_number(rwx, true)
906 umask_cache = ("%03o"):format(num) 908 umask_cache = ("%03o"):format(num)
907 return umask_cache 909 return umask_cache
908 end 910 end