From 923f37301736155e1db07e540bc0e57e211d5380 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 7 May 2019 16:51:00 -0300 Subject: cmd: fix handling of unconfigured paths in get_lua_version --- src/luarocks/cmd.lua | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index 284b1602..cb669226 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua @@ -157,18 +157,15 @@ local function get_lua_version(flags) return flags["lua-version"] end local dirs = {} - local next_i = 1 if flags["project-tree"] then - dirs[next_i] = dir.path(flags["project-tree"], "..", ".luarocks") - next_i = next_i + 1 + table.insert(dirs, dir.path(flags["project-tree"], "..", ".luarocks")) end if cfg.home_tree then - dirs[next_i] = dir.path(cfg.home_tree, ".luarocks") - next_i = next_i + 1 + table.insert(dirs, dir.path(cfg.home_tree, ".luarocks")) end - dirs[next_i] = cfg.sysconfdir - for i=1, next_i do - local f = dir.path(dirs[i], "default-lua-version.lua") + table.insert(dirs, cfg.sysconfdir) + for _, d in ipairs(dirs) do + local f = dir.path(d, "default-lua-version.lua") local mod, err = loadfile(f, "t") if mod then local pok, ver = pcall(mod) -- cgit v1.2.3-55-g6feb