aboutsummaryrefslogtreecommitdiff
path: root/src/path/filepath
diff options
context:
space:
mode:
authorDaniel Martí <mvdan@mvdan.cc>2023-09-24 14:41:10 +0100
committerDaniel Martí <mvdan@mvdan.cc>2023-09-29 09:00:12 +0000
commit8c3924c6569ceb8183c136e42c9f4b7904a0c031 (patch)
tree8464be8d01bc39e3cb0899478d4496578a06a480 /src/path/filepath
parent5351bcf8225747f0ef39afc44c0499822992ed11 (diff)
downloadgo-8c3924c6569ceb8183c136e42c9f4b7904a0c031.tar.xz
path/filepath: reuse os.ReadDir
While reading the source code, I noticed that readDir seemed extremely similar to os.ReadDir. They indeed appear to be copies. Note that there's readDirNames as well, but it has no corresponding os.ReadDirNames top-level helper to be replaced by. Change-Id: I6fe1d0aeda35dc69bb4531986fe3a21ebda1d877 Reviewed-on: https://go-review.googlesource.com/c/go/+/530795 Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/path/filepath')
-rw-r--r--src/path/filepath/path.go18
1 files changed, 1 insertions, 17 deletions
diff --git a/src/path/filepath/path.go b/src/path/filepath/path.go
index 6dcb0e1fb9..b1f1bf0e3f 100644
--- a/src/path/filepath/path.go
+++ b/src/path/filepath/path.go
@@ -463,7 +463,7 @@ func walkDir(path string, d fs.DirEntry, walkDirFn fs.WalkDirFunc) error {
return err
}
- dirs, err := readDir(path)
+ dirs, err := os.ReadDir(path)
if err != nil {
// Second call, to report ReadDir error.
err = walkDirFn(path, d, err)
@@ -580,22 +580,6 @@ func Walk(root string, fn WalkFunc) error {
return err
}
-// readDir reads the directory named by dirname and returns
-// a sorted list of directory entries.
-func readDir(dirname string) ([]fs.DirEntry, error) {
- f, err := os.Open(dirname)
- if err != nil {
- return nil, err
- }
- dirs, err := f.ReadDir(-1)
- f.Close()
- if err != nil {
- return nil, err
- }
- sort.Slice(dirs, func(i, j int) bool { return dirs[i].Name() < dirs[j].Name() })
- return dirs, nil
-}
-
// readDirNames reads the directory named by dirname and returns
// a sorted list of directory entry names.
func readDirNames(dirname string) ([]string, error) {