mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
plugin/discovery: ignore non-files when discovering
If we encounter something that isn't a file -- for example, a dangling symlink whose referent has been deleted -- we'll ignore it so that we can either later produce a "no such plugin" error or auto-install a plugin that will actually work.
This commit is contained in:
parent
3f401f0cd4
commit
12d6bc8c30
@ -3,6 +3,7 @@ package discovery
|
|||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -70,6 +71,12 @@ func findPluginPaths(kind string, dirs []string) []string {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that the file we found is usable
|
||||||
|
if !pathIsFile(absPath) {
|
||||||
|
log.Printf("[ERROR] ignoring non-file %s", absPath)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("[DEBUG] found %s %q", kind, fullName)
|
log.Printf("[DEBUG] found %s %q", kind, fullName)
|
||||||
ret = append(ret, filepath.Clean(absPath))
|
ret = append(ret, filepath.Clean(absPath))
|
||||||
continue
|
continue
|
||||||
@ -82,6 +89,12 @@ func findPluginPaths(kind string, dirs []string) []string {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that the file we found is usable
|
||||||
|
if !pathIsFile(absPath) {
|
||||||
|
log.Printf("[ERROR] ignoring non-file %s", absPath)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("[WARNING] found legacy %s %q", kind, fullName)
|
log.Printf("[WARNING] found legacy %s %q", kind, fullName)
|
||||||
|
|
||||||
ret = append(ret, filepath.Clean(absPath))
|
ret = append(ret, filepath.Clean(absPath))
|
||||||
@ -91,6 +104,17 @@ func findPluginPaths(kind string, dirs []string) []string {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns true if and only if the given path refers to a file or a symlink
|
||||||
|
// to a file.
|
||||||
|
func pathIsFile(path string) bool {
|
||||||
|
info, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return !info.IsDir()
|
||||||
|
}
|
||||||
|
|
||||||
// ResolvePluginPaths takes a list of paths to plugin executables (as returned
|
// ResolvePluginPaths takes a list of paths to plugin executables (as returned
|
||||||
// by e.g. FindPluginPaths) and produces a PluginMetaSet describing the
|
// by e.g. FindPluginPaths) and produces a PluginMetaSet describing the
|
||||||
// referenced plugins.
|
// referenced plugins.
|
||||||
|
Loading…
Reference in New Issue
Block a user