From 2de241f1010585af2528ef40ead82510afc44891 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 30 Aug 2019 11:31:14 -0300 Subject: fs: make fs reinitializable See #1069. --- src/luarocks/cmd.lua | 4 ++++ src/luarocks/fs.lua | 22 ++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index a1ec1c14..575d3223 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua @@ -511,6 +511,10 @@ function cmd.run_command(description, commands, external_namespace, ...) end ----------------------------------------------------------------------------- + -- Now that the config is fully loaded, reinitialize fs using the full + -- feature set. + fs.init() + -- if the Lua interpreter wasn't explicitly found before cfg.init, -- try again now. if not lua_found then diff --git a/src/luarocks/fs.lua b/src/luarocks/fs.lua index f3c474eb..06f7e3fd 100644 --- a/src/luarocks/fs.lua +++ b/src/luarocks/fs.lua @@ -70,17 +70,23 @@ do end function fs.init() - if fs.current_dir then - -- already initialized - return - end + local inits = {} - if not cfg.each_platform then - error("cfg is not initialized, please run cfg.init() first") + if fs.current_dir then + -- unload luarocks fs so it can be reloaded using all modules + -- providing extra functionality in the current package paths + for k, _ in pairs(fs) do + if k ~= "init" and k ~= "verbose" then + fs[k] = nil + end + end + for m, _ in pairs(package.loaded) do + if m:match("luarocks%.fs%.") then + package.loaded[m] = nil + end + end end - local inits = {} - -- Load platform-specific functions load_platform_fns("luarocks.fs.%s", inits) -- cgit v1.2.3-55-g6feb