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
|
||||
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,13 +700,13 @@ 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)
|
||||
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
|
||||
end
|
||||
if version_match and config.plugins[basename] ~= false then
|
||||
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
|
||||
|
@ -716,6 +716,7 @@ function core.load_plugins()
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return no_errors, refused_list
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue