remove duplicate tests plugins from symlinks
@@ -79,7 +79,11 @@ func getTestBinaries(streams genericclioptions.IOStreams) ([]string, error) {
}
testBinaryPath := filepath.Join(dir, f.Name())
- if testBinaries.Has(testBinaryPath) {
+ isSymlink, err := evalSymlink(testBinaryPath)
+ if err != nil {
+ log.Println(err)
+ }
+ if testBinaries.Has(testBinaryPath) || isSymlink {
continue
}
testBinaries.Insert(testBinaryPath)
@@ -115,6 +119,20 @@ type CommandOverrideVerifier struct {
seenPlugins map[string]string
}
+// evalSymlink returns true if provided path is a symlink
+func evalSymlink(path string) (bool, error) {
+ link, err := filepath.EvalSymlinks(path)
+ if err != nil {
+ return false, err
+ }
+ if len(link) != 0 {
+ if link != path {
+ return true, nil
+ }
+ }
+ return false, nil
+}
+
// Verify implements PathVerifier and determines if a given path
// is valid depending on whether or not it overwrites an existing
// kubectl command path, or a previously seen plugin.
