diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-25 19:22:16 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-26 10:13:02 -0300 |
commit | 842d7342eb12d133fa85514d801983095300e76c (patch) | |
tree | 1434ecffe84bd8e90bd5cb64cdbda96caf90271b /src | |
parent | 63a8fb17b00b8b60419ad34dae31a4143f744be5 (diff) | |
download | luarocks-842d7342eb12d133fa85514d801983095300e76c.tar.gz luarocks-842d7342eb12d133fa85514d801983095300e76c.tar.bz2 luarocks-842d7342eb12d133fa85514d801983095300e76c.zip |
fs: fix rwx_to_number, add negated mask mode
Fixes #856.
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/fs/lua.lua | 24 |
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 | ||
874 | function 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) | ||
884 | end | ||
885 | |||
874 | if posix_ok then | 886 | if posix_ok then |
875 | 887 | ||
876 | local octal_to_rwx = { | 888 | local octal_to_rwx = { |
@@ -884,16 +896,6 @@ local octal_to_rwx = { | |||
884 | ["7"] = "rwx", | 896 | ["7"] = "rwx", |
885 | } | 897 | } |
886 | 898 | ||
887 | function 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 | ||
895 | end | ||
896 | |||
897 | do | 899 | do |
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 |