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