diff options
author | Russ Cox <rsc@golang.org> | 2020-10-29 14:46:29 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2020-12-09 19:12:27 +0000 |
commit | f1980efb92c011eab71aa61b68ccf58d845d1de7 (patch) | |
tree | 8bfed500207b38cba5fc254c2531a9760d6a0154 /src/crypto | |
parent | 4f1b0a44cb46f3df28f5ef82e5769ebeac1bc493 (diff) | |
download | go-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/crypto')
-rw-r--r-- | src/crypto/x509/root_unix.go | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/crypto/x509/root_unix.go b/src/crypto/x509/root_unix.go index 3c643466ed..262fc079d5 100644 --- a/src/crypto/x509/root_unix.go +++ b/src/crypto/x509/root_unix.go @@ -8,7 +8,6 @@ package x509 import ( "io/fs" - "io/ioutil" "os" "path/filepath" "strings" @@ -82,17 +81,17 @@ func loadSystemRoots() (*CertPool, error) { return nil, firstErr } -// readUniqueDirectoryEntries is like ioutil.ReadDir but omits +// readUniqueDirectoryEntries is like os.ReadDir but omits // symlinks that point within the directory. -func readUniqueDirectoryEntries(dir string) ([]fs.FileInfo, error) { - fis, err := ioutil.ReadDir(dir) +func readUniqueDirectoryEntries(dir string) ([]fs.DirEntry, error) { + files, err := os.ReadDir(dir) if err != nil { return nil, err } - uniq := fis[:0] - for _, fi := range fis { - if !isSameDirSymlink(fi, dir) { - uniq = append(uniq, fi) + uniq := files[:0] + for _, f := range files { + if !isSameDirSymlink(f, dir) { + uniq = append(uniq, f) } } return uniq, nil @@ -100,10 +99,10 @@ func readUniqueDirectoryEntries(dir string) ([]fs.FileInfo, error) { // isSameDirSymlink reports whether fi in dir is a symlink with a // target not containing a slash. -func isSameDirSymlink(fi fs.FileInfo, dir string) bool { - if fi.Mode()&fs.ModeSymlink == 0 { +func isSameDirSymlink(f fs.DirEntry, dir string) bool { + if f.Type()&fs.ModeSymlink == 0 { return false } - target, err := os.Readlink(filepath.Join(dir, fi.Name())) + target, err := os.Readlink(filepath.Join(dir, f.Name())) return err == nil && !strings.Contains(target, "/") } |