diff options
author | daurnimator <quae@daurnimator.com> | 2018-08-14 12:33:17 +1000 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-08-14 13:25:51 -0300 |
commit | 97612b69ef22d7e595b485c2f7dd003fa7da6da2 (patch) | |
tree | 0e731af86c20653bb2ab1f34d5f326d309f39a31 | |
parent | bc187e06358a749cfc5d0974549cee7e1116f8bf (diff) | |
download | luarocks-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.lua | 15 |
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) | |||
200 | end | 200 | end |
201 | 201 | ||
202 | do | 202 | do |
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 |
214 | end | 223 | end |