From f2358a0a86ec905275d52ea7c7b148e5a5013402 Mon Sep 17 00:00:00 2001 From: Sauyon Lee Date: Wed, 4 Mar 2020 16:08:55 -0800 Subject: [PATCH] Find all go.mod files before extraction --- extractor/extractor.go | 26 ++++++++++++++++---------- extractor/gomodextractor.go | 1 - 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/extractor/extractor.go b/extractor/extractor.go index 3a318f146eb..ca99c51e87a 100644 --- a/extractor/extractor.go +++ b/extractor/extractor.go @@ -123,27 +123,33 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error { log.Printf("Walking file tree from %s to discover go.mod files...", cwd) + goModPaths := make([]string, 0, 10) + filepath.Walk(cwd, func(path string, info os.FileInfo, err error) error { if filepath.Base(path) == "go.mod" && info != nil && info.Mode().IsRegular() { if err != nil { log.Printf("Found go.mod with path %s, but encountered error %s", path, err.Error()) } - log.Printf("Extracting %s", path) - start := time.Now() - - err := extractGoMod(path) - if err != nil { - log.Printf("Failed to extract go.mod: %s", err.Error()) - } - - end := time.Since(start) - log.Printf("Done extracting %s (%dms)", path, end.Nanoseconds()/1000000) + goModPaths = append(goModPaths, path) } return nil }) + for _, path := range goModPaths { + log.Printf("Extracting %s", path) + start := time.Now() + + err := extractGoMod(path) + if err != nil { + log.Printf("Failed to extract go.mod: %s", err.Error()) + } + + end := time.Since(start) + log.Printf("Done extracting %s (%dms)", path, end.Nanoseconds()/1000000) + } + return nil } diff --git a/extractor/gomodextractor.go b/extractor/gomodextractor.go index 7d90a46648d..a59c076eb71 100644 --- a/extractor/gomodextractor.go +++ b/extractor/gomodextractor.go @@ -14,7 +14,6 @@ import ( ) func extractGoMod(path string) error { - if normPath, err := filepath.EvalSymlinks(path); err == nil { path = normPath }