aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2022-02-16 19:55:10 -0300
committerHisham Muhammad <hisham@gobolinux.org>2022-02-17 01:58:57 -0300
commit7b61fda916ed40589896e067127e9c6c35730b07 (patch)
treefa6a03f8cfec2a8ed982c301f73c93218e638ee5 /src
parent48babcc745639f417c87c08cbaf989b9f0e7fc01 (diff)
downloadluarocks-7b61fda916ed40589896e067127e9c6c35730b07.tar.gz
luarocks-7b61fda916ed40589896e067127e9c6c35730b07.tar.bz2
luarocks-7b61fda916ed40589896e067127e9c6c35730b07.zip
Always produce a default config if cfg.init() fails loading a file
This ensures that luarocks.loader() gets a baseline configuration
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/core/cfg.lua16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua
index f0e5aa93..9059098a 100644
--- a/src/luarocks/core/cfg.lua
+++ b/src/luarocks/core/cfg.lua
@@ -562,6 +562,10 @@ local cfg = {}
562function cfg.init(detected, warning) 562function cfg.init(detected, warning)
563 detected = detected or {} 563 detected = detected or {}
564 564
565 local exit_ok = true
566 local exit_err = nil
567 local exit_what = nil
568
565 local hc_ok, hardcoded = pcall(require, "luarocks.core.hardcoded") 569 local hc_ok, hardcoded = pcall(require, "luarocks.core.hardcoded")
566 if not hc_ok then 570 if not hc_ok then
567 hardcoded = {} 571 hardcoded = {}
@@ -670,7 +674,7 @@ function cfg.init(detected, warning)
670 sys_config_file = (cfg.sysconfdir .. "/" .. config_file_name):gsub("\\", "/") 674 sys_config_file = (cfg.sysconfdir .. "/" .. config_file_name):gsub("\\", "/")
671 local sys_config_ok, err = load_config_file(cfg, platforms, sys_config_file) 675 local sys_config_ok, err = load_config_file(cfg, platforms, sys_config_file)
672 if err then 676 if err then
673 return nil, err, "config" 677 exit_ok, exit_err, exit_what = nil, err, "config"
674 end 678 end
675 679
676 -- Load user configuration file (if allowed) 680 -- Load user configuration file (if allowed)
@@ -687,7 +691,7 @@ function cfg.init(detected, warning)
687 if env_value then 691 if env_value then
688 local env_ok, err = load_config_file(cfg, platforms, env_value) 692 local env_ok, err = load_config_file(cfg, platforms, env_value)
689 if err then 693 if err then
690 return nil, err, "config" 694 exit_ok, exit_err, exit_what = nil, err, "config"
691 elseif warning and not env_ok then 695 elseif warning and not env_ok then
692 warning("Warning: could not load configuration file `"..env_value.."` given in environment variable "..env_var.."\n") 696 warning("Warning: could not load configuration file `"..env_value.."` given in environment variable "..env_var.."\n")
693 end 697 end
@@ -704,7 +708,7 @@ function cfg.init(detected, warning)
704 home_config_file = (cfg.homeconfdir .. "/" .. config_file_name):gsub("\\", "/") 708 home_config_file = (cfg.homeconfdir .. "/" .. config_file_name):gsub("\\", "/")
705 home_config_ok, err = load_config_file(cfg, platforms, home_config_file) 709 home_config_ok, err = load_config_file(cfg, platforms, home_config_file)
706 if err then 710 if err then
707 return nil, err, "config" 711 exit_ok, exit_err, exit_what = nil, err, "config"
708 end 712 end
709 end 713 end
710 714
@@ -714,7 +718,7 @@ function cfg.init(detected, warning)
714 home_config_file = (cfg.homeconfdir .. "/" .. config_file_name):gsub("\\", "/") 718 home_config_file = (cfg.homeconfdir .. "/" .. config_file_name):gsub("\\", "/")
715 home_config_ok, err = load_config_file(cfg, platforms, home_config_file) 719 home_config_ok, err = load_config_file(cfg, platforms, home_config_file)
716 if err then 720 if err then
717 return nil, err, "config" 721 exit_ok, exit_err, exit_what = nil, err, "config"
718 end 722 end
719 end 723 end
720 724
@@ -723,7 +727,7 @@ function cfg.init(detected, warning)
723 project_config_file = cfg.project_dir .. "/.luarocks/" .. config_file_name 727 project_config_file = cfg.project_dir .. "/.luarocks/" .. config_file_name
724 project_config_ok, err = load_config_file(cfg, platforms, project_config_file) 728 project_config_ok, err = load_config_file(cfg, platforms, project_config_file)
725 if err then 729 if err then
726 return nil, err, "config" 730 exit_ok, exit_err, exit_what = nil, err, "config"
727 end 731 end
728 end 732 end
729 end 733 end
@@ -876,7 +880,7 @@ function cfg.init(detected, warning)
876 return table.concat(platform_keys, ", ") 880 return table.concat(platform_keys, ", ")
877 end 881 end
878 882
879 return true 883 return exit_ok, exit_err, exit_what
880end 884end
881 885
882return cfg 886return cfg