Skip to content

Commit

Permalink
Plugins: Use plugin.pluginDir as source of truth for plugin location (g…
Browse files Browse the repository at this point in the history
…rafana#36711)

* use plugin.pluginDir as source of truth for plugin location

* correct the interface
  • Loading branch information
wbrowne authored Jul 15, 2021
1 parent e82f8db commit 94688be
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/plugins/ifaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type PluginInstaller interface {
// and installs in the provided plugins directory.
Install(ctx context.Context, pluginID, version, pluginsDirectory, pluginZipURL, pluginRepoURL string) error
// Uninstall removes the specified plugin from the provided plugins directory.
Uninstall(ctx context.Context, pluginID, pluginPath string) error
Uninstall(ctx context.Context, pluginPath string) error
}

type PluginInstallerLogger interface {
Expand Down
10 changes: 4 additions & 6 deletions pkg/plugins/manager/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,20 @@ func (i *Installer) Install(ctx context.Context, pluginID, version, pluginsDir,
return err
}

// Uninstall removes the specified plugin from the provided plugins directory.
func (i *Installer) Uninstall(ctx context.Context, pluginID, pluginPath string) error {
pluginDir := filepath.Join(pluginPath, pluginID)

// Uninstall removes the specified plugin from the provided plugin directory.
func (i *Installer) Uninstall(ctx context.Context, pluginDir string) error {
// verify it's a plugin directory
if _, err := os.Stat(filepath.Join(pluginDir, "plugin.json")); err != nil {
if os.IsNotExist(err) {
if _, err := os.Stat(filepath.Join(pluginDir, "dist", "plugin.json")); err != nil {
if os.IsNotExist(err) {
return fmt.Errorf("tried to remove %s, but it doesn't seem to be a plugin", pluginPath)
return fmt.Errorf("tried to remove %s, but it doesn't seem to be a plugin", pluginDir)
}
}
}
}

i.log.Infof("Uninstalling plugin %v", pluginID)
i.log.Infof("Uninstalling plugin %v", pluginDir)

return os.RemoveAll(pluginDir)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ func (pm *PluginManager) Uninstall(ctx context.Context, pluginID string) error {
return err
}

return pm.pluginInstaller.Uninstall(ctx, pluginID, pm.Cfg.PluginsPath)
return pm.pluginInstaller.Uninstall(ctx, plugin.PluginDir)
}

func (pm *PluginManager) unregister(plugin *plugins.PluginBase) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ func (f *fakePluginInstaller) Install(ctx context.Context, pluginID, version, pl
return nil
}

func (f *fakePluginInstaller) Uninstall(ctx context.Context, pluginID, pluginPath string) error {
func (f *fakePluginInstaller) Uninstall(ctx context.Context, pluginPath string) error {
f.uninstallCount++
return nil
}
Expand Down

0 comments on commit 94688be

Please sign in to comment.