From 4c969726b78b61523f3422cbe64e8f0adb1cfac1 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 19 Mar 2015 17:08:59 -0300 Subject: Don't use user tree when running as root. Fixes #303. --- src/luarocks/cfg.lua | 2 +- src/luarocks/command_line.lua | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index ea80e5b5..b4781840 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -139,7 +139,7 @@ else cfg.home = os.getenv("HOME") or "" sys_config_dir = sys_config_dir or "/etc/luarocks" home_config_dir = cfg.home.."/.luarocks" - cfg.home_tree = cfg.home.."/.luarocks/" + cfg.home_tree = (os.getenv("USER") ~= "root") and cfg.home.."/.luarocks/" end cfg.variables = {} diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index c885575e..a92a3f9d 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua @@ -153,6 +153,11 @@ function command_line.run_command(...) replace_tree(flags, args, root_dir) end elseif flags["local"] then + if not cfg.home_tree then + die("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.") + end replace_tree(flags, args, cfg.home_tree) else local trees = cfg.rocks_trees -- cgit v1.2.3-55-g6feb