aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2020-11-04 18:20:17 -0500
committerRuss Cox <rsc@golang.org>2020-12-02 16:33:57 +0000
commitc32140fa94cfc51a2152855825f57e27ae3ba133 (patch)
treeb9777c7aff45d975f55b3987dfa440580bbb8f58 /test
parent0433845ad18a355413033bb3495ba3195f4c69ec (diff)
downloadgo-c32140fa94cfc51a2152855825f57e27ae3ba133.tar.gz
go-c32140fa94cfc51a2152855825f57e27ae3ba133.zip
all: update to use filepath.WalkDir instead of filepath.Walk
Now that filepath.WalkDir is available, it is more efficient and should be used in place of filepath.Walk. Update the tree to reflect best practices. As usual, the code compiled with Go 1.4 during bootstrap is excluded. (In this CL, that's only cmd/dist.) For #42027. Change-Id: Ib0f7b1e43e50b789052f9835a63ced701d8c411c Reviewed-on: https://go-review.googlesource.com/c/go/+/267719 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'test')
-rw-r--r--test/run.go17
-rw-r--r--test/winbatch.go6
2 files changed, 13 insertions, 10 deletions
diff --git a/test/run.go b/test/run.go
index 672861c8d7..4abf32d25c 100644
--- a/test/run.go
+++ b/test/run.go
@@ -14,6 +14,7 @@ import (
"fmt"
"hash/fnv"
"io"
+ "io/fs"
"io/ioutil"
"log"
"os"
@@ -1793,7 +1794,7 @@ func overlayDir(dstRoot, srcRoot string) error {
return err
}
- return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
+ return filepath.WalkDir(srcRoot, func(srcPath string, d fs.DirEntry, err error) error {
if err != nil || srcPath == srcRoot {
return err
}
@@ -1804,14 +1805,16 @@ func overlayDir(dstRoot, srcRoot string) error {
}
dstPath := filepath.Join(dstRoot, suffix)
- perm := info.Mode() & os.ModePerm
- if info.Mode()&os.ModeSymlink != 0 {
+ var info fs.FileInfo
+ if d.Type()&os.ModeSymlink != 0 {
info, err = os.Stat(srcPath)
- if err != nil {
- return err
- }
- perm = info.Mode() & os.ModePerm
+ } else {
+ info, err = d.Info()
}
+ if err != nil {
+ return err
+ }
+ perm := info.Mode() & os.ModePerm
// Always copy directories (don't symlink them).
// If we add a file in the overlay, we don't want to add it in the original.
diff --git a/test/winbatch.go b/test/winbatch.go
index c3b48d385c..54c2fff134 100644
--- a/test/winbatch.go
+++ b/test/winbatch.go
@@ -27,11 +27,11 @@ func main() {
// Walk the entire Go repository source tree (without GOROOT/pkg),
// skipping directories that start with "." and named "testdata",
// and ensure all .bat files found have exact CRLF line endings.
- err := filepath.Walk(runtime.GOROOT(), func(path string, fi os.FileInfo, err error) error {
+ err := filepath.WalkDir(runtime.GOROOT(), func(path string, d os.DirEntry, err error) error {
if err != nil {
return err
}
- if fi.IsDir() && (strings.HasPrefix(fi.Name(), ".") || fi.Name() == "testdata") {
+ if d.IsDir() && (strings.HasPrefix(d.Name(), ".") || d.Name() == "testdata") {
return filepath.SkipDir
}
if path == filepath.Join(runtime.GOROOT(), "pkg") {
@@ -39,7 +39,7 @@ func main() {
// Skip it to avoid false positives. (Also see golang.org/issue/37929.)
return filepath.SkipDir
}
- if filepath.Ext(fi.Name()) == ".bat" {
+ if filepath.Ext(d.Name()) == ".bat" {
enforceBatchStrictCRLF(path)
}
return nil