]> Cypherpunks repositories - gostls13.git/commitdiff
internal/copyright: skip testdata and vendor directories only
authorDmitri Shuralyov <dmitshur@golang.org>
Thu, 21 Nov 2024 17:50:14 +0000 (12:50 -0500)
committerGopher Robot <gobot@golang.org>
Thu, 21 Nov 2024 22:36:18 +0000 (22:36 +0000)
Using filepath.SkipDir without confirming that d is a directory makes
it prone to taking unintended action if a file (not a directory) with
the same name gets added.

This isn't a problem today, but we shouldn't spend human code review
time checking that this doesn't somehow happen in the future, either.

Change-Id: I29bf203ddef175c3ad23c9ddc10fa934126ac853
Reviewed-on: https://go-review.googlesource.com/c/go/+/630635
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Bypass: Dmitri Shuralyov <dmitshur@golang.org>

src/internal/copyright/copyright_test.go

index 4676f18a59fbd42e23ca8919317216c09873a86f..dbaefa92dd745b64123272e5bae3a6806779d8d2 100644 (file)
@@ -34,7 +34,7 @@ var permitted = [][]byte{
 func TestCopyright(t *testing.T) {
        buf := make([]byte, 2048)
        filepath.WalkDir(filepath.Join(testenv.GOROOT(t), "src"), func(path string, d fs.DirEntry, err error) error {
-               if d.Name() == "testdata" || d.Name() == "vendor" {
+               if d.IsDir() && (d.Name() == "testdata" || d.Name() == "vendor") {
                        return filepath.SkipDir
                }
                switch filepath.Ext(d.Name()) {