aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Smedstad <carl.smedstad@protonmail.com>2021-04-05 00:52:59 +0200
committerHisham Muhammad <hisham@gobolinux.org>2021-04-06 17:24:57 -0300
commit07d9383c1c53a0cd3967555817270a7dee9c643f (patch)
treed1ffd853f73cd5525626816446d821a8ed4e4811
parent8bc71893611b12b62dd6dd5f0e992451336b072c (diff)
downloadluarocks-07d9383c1c53a0cd3967555817270a7dee9c643f.tar.gz
luarocks-07d9383c1c53a0cd3967555817270a7dee9c643f.tar.bz2
luarocks-07d9383c1c53a0cd3967555817270a7dee9c643f.zip
Set cfg.home_tree even for root user
Don't set cfg.home_tree to nil in cfg.lua when the user is root. Instead, do explicit checks if the user is root in cmd.lua. This removes some confusion, as cfg.home_tree is later set by the default system config file, so it will show up when running 'luarocks config'.
-rw-r--r--src/luarocks/cmd.lua4
-rw-r--r--src/luarocks/core/cfg.lua4
2 files changed, 4 insertions, 4 deletions
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua
index be749c16..9255cff8 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 not cfg.home_tree then 88 if os.getenv("USER") == "root" 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 not cfg.home_tree then 645 if os.getenv("USER") == "root" 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/core/cfg.lua b/src/luarocks/core/cfg.lua
index c19f7d3b..b2b26fad 100644
--- a/src/luarocks/core/cfg.lua
+++ b/src/luarocks/core/cfg.lua
@@ -86,8 +86,8 @@ local function set_confdirs(cfg, platforms, hardcoded_sysconfdir)
86 sysconfdir = detect_sysconfdir() 86 sysconfdir = detect_sysconfdir()
87 end 87 end
88 cfg.home = os.getenv("HOME") or "" 88 cfg.home = os.getenv("HOME") or ""
89 cfg.home_tree = (os.getenv("USER") ~= "root") and cfg.home.."/.luarocks" 89 cfg.home_tree = cfg.home.."/.luarocks"
90 cfg.homeconfdir = cfg.home.."/.luarocks" 90 cfg.homeconfdir = cfg.home_tree
91 cfg.sysconfdir = sysconfdir or "/etc/luarocks" 91 cfg.sysconfdir = sysconfdir or "/etc/luarocks"
92 end 92 end
93end 93end