diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2019-08-30 11:31:14 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-08-30 16:35:44 -0300 |
| commit | 2de241f1010585af2528ef40ead82510afc44891 (patch) | |
| tree | bead8b5ef487b6de75d9859e987617b2d305d217 | |
| parent | 52b84bb504277fe571a260c2eb1bb157ed28a105 (diff) | |
| download | luarocks-2de241f1010585af2528ef40ead82510afc44891.tar.gz luarocks-2de241f1010585af2528ef40ead82510afc44891.tar.bz2 luarocks-2de241f1010585af2528ef40ead82510afc44891.zip | |
fs: make fs reinitializable
See #1069.
| -rw-r--r-- | src/luarocks/cmd.lua | 4 | ||||
| -rw-r--r-- | src/luarocks/fs.lua | 22 |
2 files changed, 18 insertions, 8 deletions
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, ...) | |||
| 511 | end | 511 | end |
| 512 | ----------------------------------------------------------------------------- | 512 | ----------------------------------------------------------------------------- |
| 513 | 513 | ||
| 514 | -- Now that the config is fully loaded, reinitialize fs using the full | ||
| 515 | -- feature set. | ||
| 516 | fs.init() | ||
| 517 | |||
| 514 | -- if the Lua interpreter wasn't explicitly found before cfg.init, | 518 | -- if the Lua interpreter wasn't explicitly found before cfg.init, |
| 515 | -- try again now. | 519 | -- try again now. |
| 516 | if not lua_found then | 520 | 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 | |||
| 70 | end | 70 | end |
| 71 | 71 | ||
| 72 | function fs.init() | 72 | function fs.init() |
| 73 | if fs.current_dir then | 73 | local inits = {} |
| 74 | -- already initialized | ||
| 75 | return | ||
| 76 | end | ||
| 77 | 74 | ||
| 78 | if not cfg.each_platform then | 75 | if fs.current_dir then |
| 79 | error("cfg is not initialized, please run cfg.init() first") | 76 | -- unload luarocks fs so it can be reloaded using all modules |
| 77 | -- providing extra functionality in the current package paths | ||
| 78 | for k, _ in pairs(fs) do | ||
| 79 | if k ~= "init" and k ~= "verbose" then | ||
| 80 | fs[k] = nil | ||
| 81 | end | ||
| 82 | end | ||
| 83 | for m, _ in pairs(package.loaded) do | ||
| 84 | if m:match("luarocks%.fs%.") then | ||
| 85 | package.loaded[m] = nil | ||
| 86 | end | ||
| 87 | end | ||
| 80 | end | 88 | end |
| 81 | 89 | ||
| 82 | local inits = {} | ||
| 83 | |||
| 84 | -- Load platform-specific functions | 90 | -- Load platform-specific functions |
| 85 | load_platform_fns("luarocks.fs.%s", inits) | 91 | load_platform_fns("luarocks.fs.%s", inits) |
| 86 | 92 | ||
