]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/github.com/hashicorp/terraform/plugin/discovery/find.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / plugin / discovery / find.go
index f5bc4c1c70ef26b12057de6f22cb73691152c7d3..f053312b00decded51691bf6960a2b95e93d62d9 100644 (file)
@@ -3,6 +3,7 @@ package discovery
 import (
        "io/ioutil"
        "log"
+       "os"
        "path/filepath"
        "strings"
 )
@@ -59,7 +60,6 @@ func findPluginPaths(kind string, dirs []string) []string {
                        fullName := item.Name()
 
                        if !strings.HasPrefix(fullName, prefix) {
-                               log.Printf("[DEBUG] skipping %q, not a %s", fullName, kind)
                                continue
                        }
 
@@ -71,6 +71,12 @@ func findPluginPaths(kind string, dirs []string) []string {
                                        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)
                                ret = append(ret, filepath.Clean(absPath))
                                continue
@@ -83,7 +89,13 @@ func findPluginPaths(kind string, dirs []string) []string {
                                continue
                        }
 
-                       log.Printf("[WARNING] found legacy %s %q", kind, fullName)
+                       // Check that the file we found is usable
+                       if !pathIsFile(absPath) {
+                               log.Printf("[ERROR] ignoring non-file %s", absPath)
+                               continue
+                       }
+
+                       log.Printf("[WARN] found legacy %s %q", kind, fullName)
 
                        ret = append(ret, filepath.Clean(absPath))
                }
@@ -92,6 +104,17 @@ func findPluginPaths(kind string, dirs []string) []string {
        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
 // by e.g. FindPluginPaths) and produces a PluginMetaSet describing the
 // referenced plugins.