aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-09-19 10:32:03 -0700
committerHisham Muhammad <hisham@gobolinux.org>2022-04-16 17:15:06 -0300
commitab5b1380c1717c22c9d6188b334e8a93c877be57 (patch)
tree7dc027994019f6b3f6b26e4daf86422e1ae0fcce
parent8757ab5a663accbd139c9cf10c4878ecd82e3f05 (diff)
downloadluarocks-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.lua4
-rw-r--r--src/luarocks/fs/lua.lua2
-rw-r--r--src/luarocks/fs/unix.lua8
-rw-r--r--src/luarocks/fs/unix/tools.lua18
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()
1045end 1045end
1046 1046
1047function fs_lua.is_superuser() 1047function fs_lua.is_superuser()
1048 return false 1048 return posix.geteuid() == 0
1049end 1049end
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()
177end 177end
178 178
179function unix.current_user()
180 return os.getenv("USER")
181end
182
183function unix.is_superuser()
184 return os.getenv("USER") == "root"
185end
186
187function unix.export_cmd(var, val) 179function unix.export_cmd(var, val)
188 return ("export %s='%s'"):format(var, val) 180 return ("export %s='%s'"):format(var, val)
189end 181end
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)
298end 298end
299 299
300function 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
312end
313
314function tools.is_superuser()
315 return fs.current_user() == "root"
316end
317
300return tools 318return tools