From 0db250104c0ebfa82f62fe9f12338565dd8f674d Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Thu, 21 Nov 2024 12:50:14 -0500 Subject: [PATCH] internal/copyright: skip testdata and vendor directories only 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 Auto-Submit: Dmitri Shuralyov Reviewed-by: Ian Lance Taylor TryBot-Bypass: Dmitri Shuralyov --- src/internal/copyright/copyright_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/copyright/copyright_test.go b/src/internal/copyright/copyright_test.go index 4676f18a59..dbaefa92dd 100644 --- a/src/internal/copyright/copyright_test.go +++ b/src/internal/copyright/copyright_test.go @@ -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()) { -- 2.48.1