Plugins: Fix module.js file not being closed when loading plugins (#66288)

* Plugins: Loader: Fix module.js file not being closed

* Plugins: LocalFS: Add comments, ensure same Read() behaviour as os.File's

* Changed comment for Close()

* Add tests for LocalFS

* "Fix" linter error

* "Fix" linter error again
This commit is contained in:
Giuseppe Guerra
2023-04-13 10:48:15 +02:00
committed by GitHub
parent 344bbb251c
commit 1c3ad81826
3 changed files with 181 additions and 4 deletions

View File

@@ -141,12 +141,16 @@ func (l *Loader) loadPlugins(ctx context.Context, src plugins.PluginSource, foun
// verify module.js exists for SystemJS to load.
// CDN plugins can be loaded with plugin.json only, so do not warn for those.
if !plugin.IsRenderer() && !plugin.IsCorePlugin() {
_, err := plugin.FS.Open("module.js")
f, err := plugin.FS.Open("module.js")
if err != nil {
if errors.Is(err, plugins.ErrFileNotExist) {
l.log.Warn("Plugin missing module.js", "pluginID", plugin.ID,
"warning", "Missing module.js, If you loaded this plugin from git, make sure to compile it.")
}
} else if f != nil {
if err := f.Close(); err != nil {
l.log.Warn("Could not close module.js", "pluginID", plugin.ID, "err", err)
}
}
}