From 654e6e76cd7e95033ae4d328fd5c7d45290efd58 Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Wed, 17 Oct 2018 13:59:53 -0400 Subject: [PATCH] gopathwalk: don't log for nonexistant root dirs If users don't have a module cache yet, or put a nonexistant directory in their GOPATH, it doesn't make sense to print an error. Just ignore it and move on. No tests; I don't think it makes sense to set up log scraping for this. Change-Id: I90719297ade37999e8b401767a0a37c940828c27 Reviewed-on: https://go-review.googlesource.com/c/142977 Run-TryBot: Heschi Kreinick TryBot-Result: Gobot Gobot Reviewed-by: Ian Cottrell --- internal/gopathwalk/walk.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/gopathwalk/walk.go b/internal/gopathwalk/walk.go index 15587abc..dc085fc1 100644 --- a/internal/gopathwalk/walk.go +++ b/internal/gopathwalk/walk.go @@ -63,6 +63,12 @@ func Walk(roots []Root, add func(root Root, dir string), opts Options) { } func walkDir(root Root, add func(Root, string), opts Options) { + if _, err := os.Stat(root.Path); os.IsNotExist(err) { + if opts.Debug { + log.Printf("skipping nonexistant directory: %v", root.Path) + } + return + } if opts.Debug { log.Printf("scanning %s", root.Path) } @@ -73,11 +79,11 @@ func walkDir(root Root, add func(Root, string), opts Options) { } w.init() if err := fastwalk.Walk(root.Path, w.walk); err != nil { - log.Printf("goimports: scanning directory %v: %v", root.Path, err) + log.Printf("gopathwalk: scanning directory %v: %v", root.Path, err) } if opts.Debug { - defer log.Printf("scanned %s", root.Path) + log.Printf("scanned %s", root.Path) } }