aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2018-08-14 12:33:17 +1000
committerHisham Muhammad <hisham@gobolinux.org>2018-08-14 13:25:51 -0300
commit97612b69ef22d7e595b485c2f7dd003fa7da6da2 (patch)
tree0e731af86c20653bb2ab1f34d5f326d309f39a31
parentbc187e06358a749cfc5d0974549cee7e1116f8bf (diff)
downloadluarocks-97612b69ef22d7e595b485c2f7dd003fa7da6da2.tar.gz
luarocks-97612b69ef22d7e595b485c2f7dd003fa7da6da2.tar.bz2
luarocks-97612b69ef22d7e595b485c2f7dd003fa7da6da2.zip
fs/unix/tools: Use 'umask -S', the only form of umask with a standardised output form
-rw-r--r--src/luarocks/fs/unix/tools.lua15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index e6be9266..31d8f0ca 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -200,15 +200,24 @@ function tools.is_file(file)
200end 200end
201 201
202do 202do
203 local function rwx_to_octal(rwx)
204 return (rwx:match "r" and 4 or 0)
205 + (rwx:match "w" and 2 or 0)
206 + (rwx:match "x" and 1 or 0)
207 end
203 local umask_cache 208 local umask_cache
204 function tools._unix_umask() 209 function tools._unix_umask()
205 if umask_cache then 210 if umask_cache then
206 return umask_cache 211 return umask_cache
207 end 212 end
208 local fd = assert(io.popen("umask")) 213 local fd = assert(io.popen("umask -S"))
209 local umask = assert(fd:read("*a")) 214 local umask = assert(fd:read("*a"))
210 umask = umask:gsub("\n", "") 215 fd:close()
211 umask_cache = umask:sub(2, 4) 216 local u, g, o = umask:match("u=([rwx]*),g=([rwx]*),o=([rwx]*)")
217 umask_cache = string.format("%d%d%d",
218 7 - rwx_to_octal(u),
219 7 - rwx_to_octal(g),
220 7 - rwx_to_octal(o))
212 return umask_cache 221 return umask_cache
213 end 222 end
214end 223end