aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/luarocks/core/cfg.lua48
1 files changed, 27 insertions, 21 deletions
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua
index 7ea86542..e24fa4f6 100644
--- a/src/luarocks/core/cfg.lua
+++ b/src/luarocks/core/cfg.lua
@@ -70,21 +70,6 @@ local function detect_sysconfdir()
70 return basedir 70 return basedir
71end 71end
72 72
73local function set_confdirs(cfg, platforms, hardcoded_sysconfdir)
74 local sysconfdir = os.getenv("LUAROCKS_SYSCONFDIR") or hardcoded_sysconfdir
75 if platforms.windows and not platforms.msys2_mingw_w64 then
76 cfg.home = os.getenv("APPDATA") or "c:"
77 cfg.home_tree = cfg.home.."/luarocks"
78 cfg.homeconfdir = cfg.home_tree
79 cfg.sysconfdir = sysconfdir or ((os.getenv("PROGRAMFILES") or "c:") .. "/luarocks")
80 else
81 cfg.home = os.getenv("HOME") or ""
82 cfg.home_tree = cfg.home.."/.luarocks"
83 cfg.homeconfdir = cfg.home_tree
84 cfg.sysconfdir = sysconfdir or detect_sysconfdir() or "/etc/luarocks"
85 end
86end
87
88local load_config_file 73local load_config_file
89do 74do
90 -- Create global environment for the config files; 75 -- Create global environment for the config files;
@@ -653,17 +638,24 @@ function cfg.init(detected, warning)
653 local sys_config_file 638 local sys_config_file
654 local home_config_file 639 local home_config_file
655 local project_config_file 640 local project_config_file
641
642 local config_file_name = "config-"..cfg.lua_version..".lua"
643
656 do 644 do
657 set_confdirs(cfg, platforms, hardcoded.SYSCONFDIR) 645 local sysconfdir = os.getenv("LUAROCKS_SYSCONFDIR") or hardcoded.SYSCONFDIR
658 local name = "config-"..cfg.lua_version..".lua" 646 if platforms.windows and not platforms.msys2_mingw_w64 then
659 sys_config_file = (cfg.sysconfdir .. "/" .. name):gsub("\\", "/") 647 cfg.home = os.getenv("APPDATA") or "c:"
660 home_config_file = (cfg.homeconfdir .. "/" .. name):gsub("\\", "/") 648 cfg.home_tree = cfg.home.."/luarocks"
661 if cfg.project_dir then 649 cfg.sysconfdir = sysconfdir or ((os.getenv("PROGRAMFILES") or "c:") .. "/luarocks")
662 project_config_file = cfg.project_dir .. "/.luarocks/" .. name 650 else
651 cfg.home = os.getenv("HOME") or ""
652 cfg.home_tree = cfg.home.."/.luarocks"
653 cfg.sysconfdir = sysconfdir or detect_sysconfdir() or "/etc/luarocks"
663 end 654 end
664 end 655 end
665 656
666 -- Load system configuration file 657 -- Load system configuration file
658 sys_config_file = (cfg.sysconfdir .. "/" .. config_file_name):gsub("\\", "/")
667 local sys_config_ok, err = load_config_file(cfg, platforms, sys_config_file) 659 local sys_config_ok, err = load_config_file(cfg, platforms, sys_config_file)
668 if err then 660 if err then
669 return nil, err, "config" 661 return nil, err, "config"
@@ -693,8 +685,21 @@ function cfg.init(detected, warning)
693 end 685 end
694 end 686 end
695 687
688 -- try XDG config home
689 if platforms.unix and not home_config_ok then
690 local xdg_config_home = os.getenv("XDG_CONFIG_HOME") or cfg.home .. "/.config"
691 cfg.homeconfdir = xdg_config_home .. "/luarocks"
692 home_config_file = (cfg.homeconfdir .. "/" .. config_file_name):gsub("\\", "/")
693 home_config_ok, err = load_config_file(cfg, platforms, home_config_file)
694 if err then
695 return nil, err, "config"
696 end
697 end
698
696 -- try the alternative defaults if there was no environment specified file or it didn't work 699 -- try the alternative defaults if there was no environment specified file or it didn't work
697 if not home_config_ok then 700 if not home_config_ok then
701 cfg.homeconfdir = cfg.home_tree
702 home_config_file = (cfg.homeconfdir .. "/" .. config_file_name):gsub("\\", "/")
698 home_config_ok, err = load_config_file(cfg, platforms, home_config_file) 703 home_config_ok, err = load_config_file(cfg, platforms, home_config_file)
699 if err then 704 if err then
700 return nil, err, "config" 705 return nil, err, "config"
@@ -703,6 +708,7 @@ function cfg.init(detected, warning)
703 708
704 -- finally, use the project-specific config file if any 709 -- finally, use the project-specific config file if any
705 if cfg.project_dir then 710 if cfg.project_dir then
711 project_config_file = cfg.project_dir .. "/.luarocks/" .. config_file_name
706 project_config_ok, err = load_config_file(cfg, platforms, project_config_file) 712 project_config_ok, err = load_config_file(cfg, platforms, project_config_file)
707 if err then 713 if err then
708 return nil, err, "config" 714 return nil, err, "config"