aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
3 files changed, 19 insertions, 9 deletions
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