imports: skip $GOPATH/src/v and $GOPATH/src/mod
These are both vgo module cache locations (originally v, soon to be mod).
Vgo dumps a lot of code into these directories.
If goimports walks in there, it takes forever.
Change-Id: I667b0a4979bf6a6b71c3651d25ec29777ff15301
Reviewed-on: https://go-review.googlesource.com/119337
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/imports/fix.go b/imports/fix.go
index ebb228d..72bc451 100644
--- a/imports/fix.go
+++ b/imports/fix.go
@@ -640,6 +640,8 @@
continue
}
testHookScanDir(srcDir)
+ srcV := filepath.Join(srcDir, "v")
+ srcMod := filepath.Join(srcDir, "mod")
walkFn := func(path string, typ os.FileMode) error {
dir := filepath.Dir(path)
if typ.IsRegular() {
@@ -648,6 +650,9 @@
// directly in your $GOPATH/src or $GOROOT/src.
return nil
}
+ if dir == srcV || dir == srcMod {
+ return filepath.SkipDir
+ }
if !strings.HasSuffix(path, ".go") {
return nil
}