]> Cypherpunks repositories - gostls13.git/commit
cmd/internal/moddeps: use filepath.SkipDir only on directories
authorDmitri Shuralyov <dmitshur@golang.org>
Wed, 19 May 2021 03:29:14 +0000 (23:29 -0400)
committerDmitri Shuralyov <dmitshur@golang.org>
Wed, 19 May 2021 15:20:08 +0000 (15:20 +0000)
commit6c1c055d1ea417d050503efe92c1eead0da68cef
tree140bc2bc75a1702f409f108e0f6910be204edaff
parent658b5e66ecbc41a49e6fb5aa63c5d9c804cf305f
cmd/internal/moddeps: use filepath.SkipDir only on directories

If a filepath.WalkFunc returns filepath.SkipDir when invoked on a
non-directory file, it skips the remaining files in the containing
directory.¹

CL 276272 accidentally added a code path that triggers this behavior
whenever filepath.Walk reaches a non-directory file that begins with
a dot, such as .gitattributes or .DS_Store, causing findGorootModules
to return early without finding any modules in GOROOT. Tests that use
it ceased to provide test coverage that the tree is tidy.

Add an explicit check for info.IsDir in the 5 places that intend to
use filepath.SkipDir to skip traversing that directory. Even paths
like GOROOT/bin and GOROOT/pkg which are unlikely to be anything but
a directory are worth checking, since the goal of moddeps is to take
a possibly problematic GOROOT tree as input and detect problems.

While the goal of findGorootModules is to find all modules in GOROOT
programmatically (in case new modules are added or modified), there
are 4 modules now that are quite likely to exist, so check for their
presence to avoid similar regressions. (It's not hard to update this
test if a well-known GOROOT module is removed or otherwise modified;
but if it becomes hard we can simplify it to check for a reasonable
number of modules instead.)

Also fix the minor skew that has crept in since the test got disabled.

¹ This wasn't necessarily an intentional design decision, but it was
  found only when Go 1.4 was already out. See CL 11690 for details.

Fixes #46254.

Change-Id: Id55ed926f8c0094b1af923070de72bacca05996f
Reviewed-on: https://go-review.googlesource.com/c/go/+/320991
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
src/cmd/internal/moddeps/moddeps_test.go
src/go.mod
src/go.sum
src/net/http/h2_bundle.go
src/net/http/socks_bundle.go
src/vendor/golang.org/x/sys/cpu/cpu.go
src/vendor/golang.org/x/sys/cpu/cpu_aix.go
src/vendor/modules.txt