[v9.5.x] Plugins: Fix module.js file not being closed when loading plugins (#66435)

* 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

(cherry picked from commit 1c3ad81826)

* trigger ci

---------

Co-authored-by: Giuseppe Guerra <giuseppe.guerra@grafana.com>
Co-authored-by: Giuseppe Guerra <to@nyo.zz.mu>
This commit is contained in:
Grot (@grafanabot)
2023-04-13 12:41:26 +02:00
committed by GitHub
co-authored by Giuseppe Guerra Giuseppe Guerra
parent 0f10b98202
commit 0f4a76c9de
3 changed files with 181 additions and 4 deletions
+5 -1
View File
@@ -152,12 +152,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.pluginsCDN.PluginSupported(plugin.ID) {
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)
}
}
}