diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-09-19 10:32:03 -0700 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2022-04-16 17:15:06 -0300 |
commit | ab5b1380c1717c22c9d6188b334e8a93c877be57 (patch) | |
tree | 7dc027994019f6b3f6b26e4daf86422e1ae0fcce | |
parent | 8757ab5a663accbd139c9cf10c4878ecd82e3f05 (diff) | |
download | luarocks-ab5b1380c1717c22c9d6188b334e8a93c877be57.tar.gz luarocks-ab5b1380c1717c22c9d6188b334e8a93c877be57.tar.bz2 luarocks-ab5b1380c1717c22c9d6188b334e8a93c877be57.zip |
fs.unix: fallback for when $USER variable is unset
Also, declare Unix version of current_user in
luarocks.fs.unix.tools, so that the pure-Lua version
based on LuaPosix takes precedence when available.
-rw-r--r-- | spec/install_spec.lua | 4 | ||||
-rw-r--r-- | src/luarocks/fs/lua.lua | 2 | ||||
-rw-r--r-- | src/luarocks/fs/unix.lua | 8 | ||||
-rw-r--r-- | src/luarocks/fs/unix/tools.lua | 18 |
4 files changed, 22 insertions, 10 deletions
diff --git a/spec/install_spec.lua b/spec/install_spec.lua index 24dbdb30..1154e9b9 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua | |||
@@ -54,7 +54,9 @@ describe("luarocks install #integration", function() | |||
54 | end) | 54 | end) |
55 | 55 | ||
56 | it("fails with local flag as root #unix", function() | 56 | it("fails with local flag as root #unix", function() |
57 | assert.is_false(run.luarocks_bool("install --local luasocket ", { USER = "root" } )) | 57 | if test_env.TYPE_TEST_ENV ~= "full" then |
58 | assert.is_false(run.luarocks_bool("install --local luasocket ", { USER = "root" } )) | ||
59 | end | ||
58 | end) | 60 | end) |
59 | 61 | ||
60 | it("fails with no downloader", function() | 62 | it("fails with no downloader", function() |
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 14bf0369..145a60de 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
@@ -1045,7 +1045,7 @@ function fs_lua.current_user() | |||
1045 | end | 1045 | end |
1046 | 1046 | ||
1047 | function fs_lua.is_superuser() | 1047 | function fs_lua.is_superuser() |
1048 | return false | 1048 | return posix.geteuid() == 0 |
1049 | end | 1049 | end |
1050 | 1050 | ||
1051 | -- This call is not available on all systems, see #677 | 1051 | -- This call is not available on all systems, see #677 |
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index 28189089..61569e30 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua | |||
@@ -176,14 +176,6 @@ function unix.tmpname() | |||
176 | return os.tmpname() | 176 | return os.tmpname() |
177 | end | 177 | end |
178 | 178 | ||
179 | function unix.current_user() | ||
180 | return os.getenv("USER") | ||
181 | end | ||
182 | |||
183 | function unix.is_superuser() | ||
184 | return os.getenv("USER") == "root" | ||
185 | end | ||
186 | |||
187 | function unix.export_cmd(var, val) | 179 | function unix.export_cmd(var, val) |
188 | return ("export %s='%s'"):format(var, val) | 180 | return ("export %s='%s'"):format(var, val) |
189 | end | 181 | end |
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index f0c0a05c..b7fd4de5 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
@@ -297,4 +297,22 @@ function tools.is_file(file) | |||
297 | return fs.execute(vars.TEST, "-f", file) | 297 | return fs.execute(vars.TEST, "-f", file) |
298 | end | 298 | end |
299 | 299 | ||
300 | function tools.current_user() | ||
301 | local user = os.getenv("USER") | ||
302 | if user then | ||
303 | return user | ||
304 | end | ||
305 | local pd = io.popen("whoami", "r") | ||
306 | if not pd then | ||
307 | return "" | ||
308 | end | ||
309 | user = pd:read("*l") | ||
310 | pd:close() | ||
311 | return user | ||
312 | end | ||
313 | |||
314 | function tools.is_superuser() | ||
315 | return fs.current_user() == "root" | ||
316 | end | ||
317 | |||
300 | return tools | 318 | return tools |