diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2012-02-14 16:05:18 -0200 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2012-02-14 16:05:18 -0200 |
| commit | 10375ec4bb162f2b992fbe477d609aa59096d7de (patch) | |
| tree | f2b23415399ecfa9a3909c9ea2c264a6421357f9 | |
| parent | ef48967491964c813354f1bd0e2560dd384cee6c (diff) | |
| download | luarocks-10375ec4bb162f2b992fbe477d609aa59096d7de.tar.gz luarocks-10375ec4bb162f2b992fbe477d609aa59096d7de.tar.bz2 luarocks-10375ec4bb162f2b992fbe477d609aa59096d7de.zip | |
Don't crash on invalid config files.
Report which config file is being loaded at luarocks --help.
Thanks to Tomas Guisasola Gorham for the suggestions.
| -rw-r--r-- | src/luarocks/cfg.lua | 17 | ||||
| -rw-r--r-- | src/luarocks/help.lua | 4 | ||||
| -rw-r--r-- | src/luarocks/persist.lua | 10 |
3 files changed, 27 insertions, 4 deletions
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 8a783237..9fce84f8 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua | |||
| @@ -91,6 +91,7 @@ end | |||
| 91 | -- Path configuration: | 91 | -- Path configuration: |
| 92 | 92 | ||
| 93 | local sys_config_file, home_config_file | 93 | local sys_config_file, home_config_file |
| 94 | local sys_config_ok, home_config_ok = false, false | ||
| 94 | if detected.windows or detected.mingw32 then | 95 | if detected.windows or detected.mingw32 then |
| 95 | home = os.getenv("APPDATA") or "c:" | 96 | home = os.getenv("APPDATA") or "c:" |
| 96 | sys_config_file = "c:/luarocks/config.lua" | 97 | sys_config_file = "c:/luarocks/config.lua" |
| @@ -106,12 +107,18 @@ end | |||
| 106 | variables = {} | 107 | variables = {} |
| 107 | rocks_trees = {} | 108 | rocks_trees = {} |
| 108 | 109 | ||
| 109 | persist.load_into_table(site_config.LUAROCKS_SYSCONFIG or sys_config_file, _M) | 110 | local ok, err = persist.load_into_table(site_config.LUAROCKS_SYSCONFIG or sys_config_file, _M) |
| 111 | if ok then | ||
| 112 | sys_config_ok = true | ||
| 113 | elseif err and ok == nil then | ||
| 114 | io.stderr:write(err.."\n") | ||
| 115 | end | ||
| 110 | 116 | ||
| 111 | if not site_config.LUAROCKS_FORCE_CONFIG then | 117 | if not site_config.LUAROCKS_FORCE_CONFIG then |
| 112 | home_config_file = os.getenv("LUAROCKS_CONFIG") or home_config_file | 118 | home_config_file = os.getenv("LUAROCKS_CONFIG") or home_config_file |
| 113 | local home_overrides = persist.load_into_table(home_config_file, { home = home }) | 119 | local home_overrides, err = persist.load_into_table(home_config_file, { home = home }) |
| 114 | if home_overrides then | 120 | if home_overrides then |
| 121 | home_config_ok = true | ||
| 115 | local util = require("luarocks.util") | 122 | local util = require("luarocks.util") |
| 116 | if home_overrides.rocks_trees then | 123 | if home_overrides.rocks_trees then |
| 117 | _M.rocks_trees = nil | 124 | _M.rocks_trees = nil |
| @@ -120,6 +127,8 @@ if not site_config.LUAROCKS_FORCE_CONFIG then | |||
| 120 | _M.rocks_servers = nil | 127 | _M.rocks_servers = nil |
| 121 | end | 128 | end |
| 122 | util.deep_merge(_M, home_overrides) | 129 | util.deep_merge(_M, home_overrides) |
| 130 | elseif err and home_overrides == nil then | ||
| 131 | io.stderr:write(err.."\n") | ||
| 123 | end | 132 | end |
| 124 | end | 133 | end |
| 125 | 134 | ||
| @@ -404,6 +413,10 @@ for _,tree in ipairs(rocks_trees) do | |||
| 404 | end | 413 | end |
| 405 | end | 414 | end |
| 406 | 415 | ||
| 416 | function which_config() | ||
| 417 | return sys_config_file, sys_config_ok, home_config_file, home_config_ok | ||
| 418 | end | ||
| 419 | |||
| 407 | --- Check if platform was detected | 420 | --- Check if platform was detected |
| 408 | -- @param query string: The platform name to check. | 421 | -- @param query string: The platform name to check. |
| 409 | -- @return boolean: true if LuaRocks is currently running on queried platform. | 422 | -- @return boolean: true if LuaRocks is currently running on queried platform. |
diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua index 718580ce..6272d213 100644 --- a/src/luarocks/help.lua +++ b/src/luarocks/help.lua | |||
| @@ -25,9 +25,13 @@ function run(...) | |||
| 25 | local flags, command = util.parse_flags(...) | 25 | local flags, command = util.parse_flags(...) |
| 26 | 26 | ||
| 27 | if not command then | 27 | if not command then |
| 28 | local sys_file, sys_ok, home_file, home_ok = cfg.which_config() | ||
| 28 | util.printout([[ | 29 | util.printout([[ |
| 29 | LuaRocks ]]..cfg.program_version..[[, a module deployment system for Lua | 30 | LuaRocks ]]..cfg.program_version..[[, a module deployment system for Lua |
| 30 | 31 | ||
| 32 | Using system configuration file: ]]..sys_file .. " (" .. (sys_ok and "ok" or "failed") ..[[) | ||
| 33 | and user configuration file: ]]..home_file .. " (" .. (home_ok and "ok" or "failed") ..[[) | ||
| 34 | |||
| 31 | ]]..program_name..[[ - ]]..program_description..[[ | 35 | ]]..program_name..[[ - ]]..program_description..[[ |
| 32 | 36 | ||
| 33 | usage: ]]..program_name..[[ [--from=<server> | --only-from=<server>] [--to=<tree>] [VAR=VALUE]... <command> [<argument>] | 37 | usage: ]]..program_name..[[ [--from=<server> | --only-from=<server>] [--to=<tree>] [VAR=VALUE]... <command> [<argument>] |
diff --git a/src/luarocks/persist.lua b/src/luarocks/persist.lua index 91c28a32..6d411e0f 100644 --- a/src/luarocks/persist.lua +++ b/src/luarocks/persist.lua | |||
| @@ -20,11 +20,17 @@ function load_into_table(filename, tbl) | |||
| 20 | 20 | ||
| 21 | local chunk, err = loadfile(filename) | 21 | local chunk, err = loadfile(filename) |
| 22 | if not chunk then | 22 | if not chunk then |
| 23 | return nil, err | 23 | if err:sub(1,5) ~= filename:sub(1,5) then |
| 24 | return false, err | ||
| 25 | end | ||
| 26 | return nil, "Error loading file: "..err | ||
| 24 | end | 27 | end |
| 25 | local result = tbl or {} | 28 | local result = tbl or {} |
| 26 | setfenv(chunk, result) | 29 | setfenv(chunk, result) |
| 27 | chunk() | 30 | local ok, err = pcall(chunk) |
| 31 | if not ok then | ||
| 32 | return nil, "Error running file: "..err | ||
| 33 | end | ||
| 28 | return result | 34 | return result |
| 29 | end | 35 | end |
| 30 | 36 | ||
