diff options
| author | Carl Smedstad <carl.smedstad@protonmail.com> | 2021-04-05 20:48:25 +0200 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2021-04-06 17:24:57 -0300 |
| commit | 09ed8630f74333eff0bb04ed1dd392fead048347 (patch) | |
| tree | 7f6ba2c42dab53c1ea79f6200c9193a0a9387676 | |
| parent | 2360071b5a723b02ec80251b569dd3c5e2f9feaa (diff) | |
| download | luarocks-09ed8630f74333eff0bb04ed1dd392fead048347.tar.gz luarocks-09ed8630f74333eff0bb04ed1dd392fead048347.tar.bz2 luarocks-09ed8630f74333eff0bb04ed1dd392fead048347.zip | |
Add function fs.is_superuser()
For environments other than UNIX, this will return false.
Suggested by @hishamhm.
| -rw-r--r-- | src/luarocks/cmd.lua | 4 | ||||
| -rw-r--r-- | src/luarocks/fs/lua.lua | 4 | ||||
| -rw-r--r-- | src/luarocks/fs/unix.lua | 4 | ||||
| -rw-r--r-- | src/luarocks/fs/win32.lua | 4 |
4 files changed, 14 insertions, 2 deletions
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index 9255cff8..bc965af4 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua | |||
| @@ -85,7 +85,7 @@ do | |||
| 85 | replace_tree(args, root_dir) | 85 | replace_tree(args, root_dir) |
| 86 | end | 86 | end |
| 87 | elseif args["local"] then | 87 | elseif args["local"] then |
| 88 | if os.getenv("USER") == "root" then | 88 | if fs.is_superuser() then |
| 89 | return nil, "The --local flag is meant for operating in a user's home directory.\n".. | 89 | return nil, "The --local flag is meant for operating in a user's home directory.\n".. |
| 90 | "You are running as a superuser, which is intended for system-wide operation.\n".. | 90 | "You are running as a superuser, which is intended for system-wide operation.\n".. |
| 91 | "To force using the superuser's home, use --tree explicitly." | 91 | "To force using the superuser's home, use --tree explicitly." |
| @@ -642,7 +642,7 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 642 | end | 642 | end |
| 643 | 643 | ||
| 644 | -- if running as superuser, use system cache dir | 644 | -- if running as superuser, use system cache dir |
| 645 | if os.getenv("USER") == "root" then | 645 | if fs.is_superuser() then |
| 646 | cfg.local_cache = dir.path(fs.system_cache_dir(), "luarocks") | 646 | cfg.local_cache = dir.path(fs.system_cache_dir(), "luarocks") |
| 647 | end | 647 | end |
| 648 | 648 | ||
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 0e98449a..6bd80485 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
| @@ -1034,6 +1034,10 @@ function fs_lua.current_user() | |||
| 1034 | return posix.getpwuid(posix.geteuid()).pw_name | 1034 | return posix.getpwuid(posix.geteuid()).pw_name |
| 1035 | end | 1035 | end |
| 1036 | 1036 | ||
| 1037 | function fs_lua.is_superuser() | ||
| 1038 | return false | ||
| 1039 | end | ||
| 1040 | |||
| 1037 | -- This call is not available on all systems, see #677 | 1041 | -- This call is not available on all systems, see #677 |
| 1038 | if posix.mkdtemp then | 1042 | if posix.mkdtemp then |
| 1039 | 1043 | ||
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index d5b36127..2c66eaa3 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua | |||
| @@ -179,6 +179,10 @@ function unix.current_user() | |||
| 179 | return os.getenv("USER") | 179 | return os.getenv("USER") |
| 180 | end | 180 | end |
| 181 | 181 | ||
| 182 | function unix.is_superuser() | ||
| 183 | return os.getenv("USER") == "root" | ||
| 184 | end | ||
| 185 | |||
| 182 | function unix.export_cmd(var, val) | 186 | function unix.export_cmd(var, val) |
| 183 | return ("export %s='%s'"):format(var, val) | 187 | return ("export %s='%s'"):format(var, val) |
| 184 | end | 188 | end |
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index 49de8e97..6d869d99 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua | |||
| @@ -351,6 +351,10 @@ function win32.current_user() | |||
| 351 | return os.getenv("USERNAME") | 351 | return os.getenv("USERNAME") |
| 352 | end | 352 | end |
| 353 | 353 | ||
| 354 | function win32.is_superuser() | ||
| 355 | return false | ||
| 356 | end | ||
| 357 | |||
| 354 | function win32.export_cmd(var, val) | 358 | function win32.export_cmd(var, val) |
| 355 | return ("SET %s=%s"):format(var, val) | 359 | return ("SET %s=%s"):format(var, val) |
| 356 | end | 360 | end |
