From 07d9383c1c53a0cd3967555817270a7dee9c643f Mon Sep 17 00:00:00 2001 From: Carl Smedstad Date: Mon, 5 Apr 2021 00:52:59 +0200 Subject: 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'. --- src/luarocks/cmd.lua | 4 ++-- src/luarocks/core/cfg.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') 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 replace_tree(args, root_dir) end elseif args["local"] then - if not cfg.home_tree then + if os.getenv("USER") == "root" then return nil, "The --local flag is meant for operating in a user's home directory.\n".. "You are running as a superuser, which is intended for system-wide operation.\n".. "To force using the superuser's home, use --tree explicitly." @@ -642,7 +642,7 @@ function cmd.run_command(description, commands, external_namespace, ...) end -- if running as superuser, use system cache dir - if not cfg.home_tree then + if os.getenv("USER") == "root" then cfg.local_cache = dir.path(fs.system_cache_dir(), "luarocks") end 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) sysconfdir = detect_sysconfdir() end cfg.home = os.getenv("HOME") or "" - cfg.home_tree = (os.getenv("USER") ~= "root") and cfg.home.."/.luarocks" - cfg.homeconfdir = cfg.home.."/.luarocks" + cfg.home_tree = cfg.home.."/.luarocks" + cfg.homeconfdir = cfg.home_tree cfg.sysconfdir = sysconfdir or "/etc/luarocks" end end -- cgit v1.2.3-55-g6feb