make user plugin take precedence over system plugins (#244)

This commit is contained in:
Takase 2021-06-03 04:53:42 +08:00 committed by GitHub
parent a3e04a209c
commit 864180e408
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 17 deletions

View File

@ -714,24 +714,28 @@ function core.load_plugins()
userdir = {dir = USERDIR, plugins = {}}, userdir = {dir = USERDIR, plugins = {}},
datadir = {dir = DATADIR, plugins = {}}, datadir = {dir = DATADIR, plugins = {}},
} }
for _, root_dir in ipairs {USERDIR, DATADIR} do local files = {}
for _, root_dir in ipairs {DATADIR, USERDIR} do
local plugin_dir = root_dir .. "/plugins" local plugin_dir = root_dir .. "/plugins"
local files = system.list_dir(plugin_dir) for _, filename in ipairs(system.list_dir(plugin_dir) or {}) do
for _, filename in ipairs(files or {}) do files[filename] = plugin_dir -- user plugins will always replace system plugins
local basename = filename:match("(.-)%.lua$") or filename end
local version_match = check_plugin_version(plugin_dir .. '/' .. filename) end
if not version_match then
core.log_quiet("Version mismatch for plugin %q from %s", basename, plugin_dir) for filename, plugin_dir in pairs(files) do
local ls = refused_list[root_dir == USERDIR and 'userdir' or 'datadir'].plugins local basename = filename:match("(.-)%.lua$") or filename
ls[#ls + 1] = filename local version_match = check_plugin_version(plugin_dir .. '/' .. filename)
end if not version_match then
if version_match and config[basename] ~= false then core.log_quiet("Version mismatch for plugin %q from %s", basename, plugin_dir)
local modname = "plugins." .. basename local ls = refused_list[root_dir == USERDIR and 'userdir' or 'datadir'].plugins
local ok = core.try(require, modname) ls[#ls + 1] = filename
if ok then core.log_quiet("Loaded plugin %q from %s", basename, plugin_dir) end end
if not ok then if version_match and config[basename] ~= false then
no_errors = false local modname = "plugins." .. basename
end local ok = core.try(require, modname)
if ok then core.log_quiet("Loaded plugin %q from %s", basename, plugin_dir) end
if not ok then
no_errors = false
end end
end end
end end