From 8fa6f9498153576ea8acc46dc42831586254bacb Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 13 May 2024 11:45:18 +0200 Subject: [PATCH] chore: comments of #4125 (#4135) * fix(plugins): correct relative path support * updates * helper --------- Co-authored-by: Danilo Pantani --- ignite/config/plugins/config.go | 7 ++++++- ignite/services/plugin/plugin.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ignite/config/plugins/config.go b/ignite/config/plugins/config.go index 5142fd3818..5a3b4f7986 100644 --- a/ignite/config/plugins/config.go +++ b/ignite/config/plugins/config.go @@ -76,6 +76,11 @@ func RemoveDuplicates(plugins []Plugin) (unique []Plugin) { return unique } +// IsLocalPath returns true if the path is a local directory. +func IsLocalPath(path string) bool { + return strings.HasPrefix(path, "/") || strings.HasPrefix(path, ".") || strings.HasPrefix(path, "~") +} + // IsGlobal returns whether the plugin is installed globally or locally for a chain. func (p Plugin) IsGlobal() bool { return p.Global @@ -83,7 +88,7 @@ func (p Plugin) IsGlobal() bool { // IsLocalPath returns true if the plugin path is a local directory. func (p Plugin) IsLocalPath() bool { - return strings.HasPrefix(p.Path, "/") || strings.HasPrefix(p.Path, ".") || strings.HasPrefix(p.Path, "~") + return IsLocalPath(p.Path) } // HasPath verifies if a plugin has the given path regardless of version. diff --git a/ignite/services/plugin/plugin.go b/ignite/services/plugin/plugin.go index ac3696593a..6955d14ab7 100644 --- a/ignite/services/plugin/plugin.go +++ b/ignite/services/plugin/plugin.go @@ -143,7 +143,7 @@ func newPlugin(pluginsDir string, cp pluginsconfig.Plugin, options ...Option) *P } // This is a local plugin, check if the file exists - if tp := (&Plugin{Plugin: pluginsconfig.Plugin{Path: pluginPath}}); tp.IsLocalPath() { + if pluginsconfig.IsLocalPath(pluginPath) { // if directory is relative, make it absolute if !filepath.IsAbs(pluginPath) { pluginPathAbs, err := filepath.Abs(pluginPath)