diff --git a/extractor/cli/go-autobuilder/go-autobuilder.go b/extractor/cli/go-autobuilder/go-autobuilder.go index 75503aaeeec..99f9af145c9 100644 --- a/extractor/cli/go-autobuilder/go-autobuilder.go +++ b/extractor/cli/go-autobuilder/go-autobuilder.go @@ -244,7 +244,10 @@ func main() { // skip the dependency installation step and run the extractor with `-mod=vendor` if util.FileExists("vendor/modules.txt") { modMode = ModVendor + } else if util.DirExists("vendor") { + modMode = modModIfSupported() } + if modMode == ModVendor { // fix go vendor issues with go versions >= 1.14 when no go version is specified in the go.mod // if this is the case, and dependencies were vendored with an old go version (and therefore diff --git a/extractor/util/util.go b/extractor/util/util.go index c8eeb33f484..a592224672c 100644 --- a/extractor/util/util.go +++ b/extractor/util/util.go @@ -91,3 +91,12 @@ func FileExists(filename string) bool { } return err == nil && !info.IsDir() } + +// DirExists tests whether `filename` exists and is a directory. +func DirExists(filename string) bool { + info, err := os.Stat(filename) + if err != nil && !os.IsNotExist(err) { + log.Printf("Unable to stat %s: %s\n", filename, err.Error()) + } + return err == nil && info.IsDir() +}