fix(plugin): dont allow dir changes when we already loaded files from the plugin's old dir. Show an error in this case. Fixes #993

This commit is contained in:
Folke Lemaitre 2023-10-15 08:51:54 +02:00
parent 3dc413d6fd
commit c8e2091e6d
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
3 changed files with 13 additions and 2 deletions

View file

@ -459,10 +459,19 @@ function Spec:merge(old, new)
end
local new_dir = new._.dir or old._.dir or (new.name and (Config.options.root .. "/" .. new.name)) or nil
if new_dir ~= new.dir then
self:warn("Plugin `" .. new.name .. "` changed `dir`:\n- from: `" .. new.dir .. "`\n- to: `" .. new_dir .. "`")
if new_dir ~= old.dir then
local msg = "Plugin `" .. new.name .. "` changed `dir`:\n- from: `" .. old.dir .. "`\n- to: `" .. new_dir .. "`"
if new._.rtp_loaded or old._.rtp_loaded then
msg = msg
.. "\n\nThis plugin was already partially loaded, so we did not change it's `dir`.\nPlease fix your config."
self:error(msg)
new_dir = old.dir
else
self:warn(msg)
end
end
new.dir = new_dir
new._.rtp_loaded = new._.rtp_loaded or old._.rtp_loaded
new._.super = old
setmetatable(new, { __index = old })