diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2018-05-23 14:55:14 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-05-31 11:16:09 -0300 |
| commit | aecf82e80e1a450857efe55c6dfe3be4354fab75 (patch) | |
| tree | f214c05c7612565beaf958b1ac6077d740ddaa29 | |
| parent | 6d22624e505d81ce58de2343a86c960518573e85 (diff) | |
| download | luarocks-aecf82e80e1a450857efe55c6dfe3be4354fab75.tar.gz luarocks-aecf82e80e1a450857efe55c6dfe3be4354fab75.tar.bz2 luarocks-aecf82e80e1a450857efe55c6dfe3be4354fab75.zip | |
cfg: load_config_file is only used with one file at a time now
| -rw-r--r-- | src/luarocks/core/cfg.lua | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index 834dba79..a17ca509 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua | |||
| @@ -200,22 +200,19 @@ local merge_overrides = function(overrides) | |||
| 200 | util.deep_merge(cfg, overrides) | 200 | util.deep_merge(cfg, overrides) |
| 201 | end | 201 | end |
| 202 | 202 | ||
| 203 | -- load config file from a list until first succesful one. Info is | 203 | -- Load config file and merge its contents into the `cfg` module table. |
| 204 | -- added to `cfg` module table, returns filepath of succesfully loaded | 204 | -- @return filepath of succesfully loaded file or nil if it failed |
| 205 | -- file or nil if it failed | 205 | local load_config_file = function(filepath) |
| 206 | local load_config_file = function(list) | 206 | local result, err, errcode = persist.load_into_table(filepath, env_for_config_file()) |
| 207 | for _, filepath in ipairs(list) do | 207 | if (not result) and errcode ~= "open" then |
| 208 | local result, err, errcode = persist.load_into_table(filepath, env_for_config_file()) | 208 | -- errcode is either "load" or "run"; bad config file, so error out |
| 209 | if (not result) and errcode ~= "open" then | 209 | io.stderr:write(err.."\n") |
| 210 | -- errcode is either "load" or "run"; bad config file, so error out | 210 | os.exit(cfg.errorcodes.CONFIGFILE) |
| 211 | io.stderr:write(err.."\n") | 211 | end |
| 212 | os.exit(cfg.errorcodes.CONFIGFILE) | 212 | if result then |
| 213 | end | 213 | -- success in loading and running, merge contents and exit |
| 214 | if result then | 214 | merge_overrides(result) |
| 215 | -- succes in loading and running, merge contents and exit | 215 | return filepath |
| 216 | merge_overrides(result) | ||
| 217 | return filepath | ||
| 218 | end | ||
| 219 | end | 216 | end |
| 220 | return nil -- nothing was loaded | 217 | return nil -- nothing was loaded |
| 221 | end | 218 | end |
| @@ -224,9 +221,9 @@ end | |||
| 224 | -- Load system configuration file | 221 | -- Load system configuration file |
| 225 | do | 222 | do |
| 226 | sys_config_file_default = sys_config_dir.."/config-"..cfg.lua_version..".lua" | 223 | sys_config_file_default = sys_config_dir.."/config-"..cfg.lua_version..".lua" |
| 227 | sys_config_file = load_config_file({ | 224 | sys_config_file = load_config_file( |
| 228 | site_config.LUAROCKS_SYSCONFIG or sys_config_file_default, | 225 | site_config.LUAROCKS_SYSCONFIG or sys_config_file_default |
| 229 | }) | 226 | ) |
| 230 | sys_config_ok = (sys_config_file ~= nil) | 227 | sys_config_ok = (sys_config_file ~= nil) |
| 231 | end | 228 | end |
| 232 | 229 | ||
| @@ -244,8 +241,7 @@ if not site_config.LUAROCKS_FORCE_CONFIG then | |||
| 244 | 241 | ||
| 245 | -- first try environment provided file, so we can explicitly warn when it is missing | 242 | -- first try environment provided file, so we can explicitly warn when it is missing |
| 246 | if config_env_value then | 243 | if config_env_value then |
| 247 | local list = { config_env_value } | 244 | home_config_file = load_config_file(config_env_value) |
| 248 | home_config_file = load_config_file(list) | ||
| 249 | home_config_ok = (home_config_file ~= nil) | 245 | home_config_ok = (home_config_file ~= nil) |
| 250 | if not home_config_ok then | 246 | if not home_config_ok then |
| 251 | io.stderr:write("Warning: could not load configuration file `"..config_env_value.."` given in environment variable "..config_env_var.."\n") | 247 | io.stderr:write("Warning: could not load configuration file `"..config_env_value.."` given in environment variable "..config_env_var.."\n") |
| @@ -254,10 +250,7 @@ if not site_config.LUAROCKS_FORCE_CONFIG then | |||
| 254 | 250 | ||
| 255 | -- try the alternative defaults if there was no environment specified file or it didn't work | 251 | -- try the alternative defaults if there was no environment specified file or it didn't work |
| 256 | if not home_config_ok then | 252 | if not home_config_ok then |
| 257 | local list = { | 253 | home_config_file = load_config_file(home_config_file_default) |
| 258 | home_config_file_default, | ||
| 259 | } | ||
| 260 | home_config_file = load_config_file(list) | ||
| 261 | home_config_ok = (home_config_file ~= nil) | 254 | home_config_ok = (home_config_file ~= nil) |
| 262 | end | 255 | end |
| 263 | end | 256 | end |
