From 97612b69ef22d7e595b485c2f7dd003fa7da6da2 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Tue, 14 Aug 2018 12:33:17 +1000 Subject: fs/unix/tools: Use 'umask -S', the only form of umask with a standardised output form --- src/luarocks/fs/unix/tools.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src') 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) end do + local function rwx_to_octal(rwx) + return (rwx:match "r" and 4 or 0) + + (rwx:match "w" and 2 or 0) + + (rwx:match "x" and 1 or 0) + end local umask_cache function tools._unix_umask() if umask_cache then return umask_cache end - local fd = assert(io.popen("umask")) + local fd = assert(io.popen("umask -S")) local umask = assert(fd:read("*a")) - umask = umask:gsub("\n", "") - umask_cache = umask:sub(2, 4) + fd:close() + local u, g, o = umask:match("u=([rwx]*),g=([rwx]*),o=([rwx]*)") + umask_cache = string.format("%d%d%d", + 7 - rwx_to_octal(u), + 7 - rwx_to_octal(g), + 7 - rwx_to_octal(o)) return umask_cache end end -- cgit v1.2.3-55-g6feb