Plugins: Use plugin.pluginDir as source of truth for plugin location (#36711)

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

* correct the interface
This commit is contained in:
Will Browne 2021-07-15 00:08:25 -07:00 committed by GitHub
parent e82f8dbef9
commit 94688be398
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 9 deletions

View File

@ -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 {

View File

@ -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)
}

View File

@ -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 {

View File

@ -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
}