Only load plugins that are lua files

Before trying to load a plugin or checking its version verify if it
looks like a lua file.

Close issue #349.
This commit is contained in:
Francesco Abbate 2021-07-27 23:16:33 +02:00
parent af22a6a824
commit 8103f21991
1 changed files with 15 additions and 14 deletions

View File

@ -664,8 +664,8 @@ local function check_plugin_version(filename)
if info ~= nil and info.type == "dir" then
filename = filename .. "/init.lua"
info = system.get_file_info(filename)
if not info then return true end
end
if not info or not filename:match("%.lua$") then return false end
local f = io.open(filename, "r")
if not f then return false end
local version_match = false
@ -685,7 +685,7 @@ local function check_plugin_version(filename)
end
end
f:close()
return version_match
return true, version_match
end
@ -700,18 +700,19 @@ function core.load_plugins()
local files = system.list_dir(plugin_dir)
for _, filename in ipairs(files or {}) do
local basename = filename:match("(.-)%.lua$") or filename
local version_match = check_plugin_version(plugin_dir .. '/' .. filename)
if not version_match then
core.log_quiet("Version mismatch for plugin %q from %s", basename, plugin_dir)
local ls = refused_list[root_dir == USERDIR and 'userdir' or 'datadir'].plugins
ls[#ls + 1] = filename
end
if version_match and config.plugins[basename] ~= false then
local modname = "plugins." .. basename
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
local is_lua_file, version_match = check_plugin_version(plugin_dir .. '/' .. filename)
if is_lua_file then
if not version_match then
core.log_quiet("Version mismatch for plugin %q from %s", basename, plugin_dir)
local ls = refused_list[root_dir == USERDIR and 'userdir' or 'datadir'].plugins
ls[#ls + 1] = filename
elseif config.plugins[basename] ~= false then
local modname = "plugins." .. basename
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