aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modcmd/vendor.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2020-10-29 14:46:29 -0400
committerRuss Cox <rsc@golang.org>2020-12-09 19:12:27 +0000
commitf1980efb92c011eab71aa61b68ccf58d845d1de7 (patch)
tree8bfed500207b38cba5fc254c2531a9760d6a0154 /src/cmd/go/internal/modcmd/vendor.go
parent4f1b0a44cb46f3df28f5ef82e5769ebeac1bc493 (diff)
downloadgo-f1980efb92c011eab71aa61b68ccf58d845d1de7.tar.gz
go-f1980efb92c011eab71aa61b68ccf58d845d1de7.zip
all: update to use os.ReadDir where appropriate
os.ReadDir is a replacement for ioutil.ReadDir that returns a slice of fs.DirEntry instead of fs.FileInfo, meaning it is the more efficient form. This CL updates call sites throughout the Go source tree wherever possible. As usual, code built using the Go 1.4 bootstrap toolchain is not included. There is also a use in go/build that appears in the public API and can't be changed, at least not without additional changes. Fixes #42026. Change-Id: Icfc9dd52c6045020f6830e22c72128499462d561 Reviewed-on: https://go-review.googlesource.com/c/go/+/266366 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modcmd/vendor.go')
-rw-r--r--src/cmd/go/internal/modcmd/vendor.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/cmd/go/internal/modcmd/vendor.go b/src/cmd/go/internal/modcmd/vendor.go
index 390a195547..1bbb57d353 100644
--- a/src/cmd/go/internal/modcmd/vendor.go
+++ b/src/cmd/go/internal/modcmd/vendor.go
@@ -10,7 +10,6 @@ import (
"fmt"
"io"
"io/fs"
- "io/ioutil"
"os"
"path/filepath"
"sort"
@@ -244,7 +243,7 @@ var metaPrefixes = []string{
}
// matchMetadata reports whether info is a metadata file.
-func matchMetadata(dir string, info fs.FileInfo) bool {
+func matchMetadata(dir string, info fs.DirEntry) bool {
name := info.Name()
for _, p := range metaPrefixes {
if strings.HasPrefix(name, p) {
@@ -255,7 +254,7 @@ func matchMetadata(dir string, info fs.FileInfo) bool {
}
// matchPotentialSourceFile reports whether info may be relevant to a build operation.
-func matchPotentialSourceFile(dir string, info fs.FileInfo) bool {
+func matchPotentialSourceFile(dir string, info fs.DirEntry) bool {
if strings.HasSuffix(info.Name(), "_test.go") {
return false
}
@@ -281,8 +280,8 @@ func matchPotentialSourceFile(dir string, info fs.FileInfo) bool {
}
// copyDir copies all regular files satisfying match(info) from src to dst.
-func copyDir(dst, src string, match func(dir string, info fs.FileInfo) bool) {
- files, err := ioutil.ReadDir(src)
+func copyDir(dst, src string, match func(dir string, info fs.DirEntry) bool) {
+ files, err := os.ReadDir(src)
if err != nil {
base.Fatalf("go mod vendor: %v", err)
}
@@ -290,7 +289,7 @@ func copyDir(dst, src string, match func(dir string, info fs.FileInfo) bool) {
base.Fatalf("go mod vendor: %v", err)
}
for _, file := range files {
- if file.IsDir() || !file.Mode().IsRegular() || !match(src, file) {
+ if file.IsDir() || !file.Type().IsRegular() || !match(src, file) {
continue
}
r, err := os.Open(filepath.Join(src, file.Name()))