Return error from FindPlugin and use Path from the installer

Signed-off-by: Suleiman Dibirov <idsulik@gmail.com>
pull/31404/head
Suleiman Dibirov 3 months ago
parent bb917b8a83
commit b1b04592a2

@ -91,7 +91,7 @@ func (i *HTTPInstaller) Install() error {
return fmt.Errorf("failed to extract plugin metadata from tarball: %w", err)
}
filename := fmt.Sprintf("%s-%s.tgz", metadata.Name, metadata.Version)
pluginsPath := helmpath.DataPath("plugins")
pluginsPath := filepath.Dir(i.Path())
foundPlugins, err := plugin.FindPlugins([]string{pluginsPath}, plugin.Descriptor{Name: metadata.Name})
if err != nil {
return fmt.Errorf("failed to search for existing plugins: %w", err)

@ -133,7 +133,7 @@ func (i *LocalInstaller) installFromArchive() error {
return fmt.Errorf("failed to extract plugin metadata from tarball: %w", err)
}
filename := fmt.Sprintf("%s-%s.tgz", metadata.Name, metadata.Version)
pluginsPath := helmpath.DataPath("plugins")
pluginsPath := filepath.Dir(i.Path())
foundPlugins, err := plugin.FindPlugins([]string{pluginsPath}, plugin.Descriptor{Name: metadata.Name})
if err != nil {
return fmt.Errorf("failed to search for existing plugins: %w", err)

@ -101,7 +101,7 @@ func (i *OCIInstaller) Install() error {
return fmt.Errorf("failed to extract plugin metadata from tarball: %w", err)
}
filename := fmt.Sprintf("%s-%s.tgz", metadata.Name, metadata.Version)
pluginsPath := helmpath.DataPath("plugins")
pluginsPath := filepath.Dir(i.Path())
foundPlugins, err := plugin.FindPlugins([]string{pluginsPath}, plugin.Descriptor{Name: metadata.Name})
if err != nil {
return fmt.Errorf("failed to search for existing plugins: %w", err)

@ -21,6 +21,7 @@ import (
stdfs "io/fs"
"log/slog"
"os"
"path/filepath"
"sort"
"github.com/Masterminds/semver/v3"
@ -100,7 +101,11 @@ func (i *VCSInstaller) Install() error {
metadata := p.Metadata()
// Check if a plugin with the same name already exists
foundPlugins, _ := plugin.FindPlugins([]string{i.PluginsDirectory}, plugin.Descriptor{Name: metadata.Name})
pluginsPath := filepath.Dir(i.Path())
foundPlugins, err := plugin.FindPlugins([]string{pluginsPath}, plugin.Descriptor{Name: metadata.Name})
if err != nil {
return fmt.Errorf("failed to search for existing plugins: %w", err)
}
if len(foundPlugins) > 0 {
return fmt.Errorf("plugin %q already exists at %q", metadata.Name, foundPlugins[0].Dir())
}

Loading…
Cancel
Save