]> Cypherpunks.ru repositories - gostls13.git/commitdiff
path/filepath: reuse os.ReadDir
authorDaniel Martí <mvdan@mvdan.cc>
Sun, 24 Sep 2023 13:41:10 +0000 (14:41 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Fri, 29 Sep 2023 09:00:12 +0000 (09:00 +0000)
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>

src/path/filepath/path.go

index 6dcb0e1fb9ea66387eac6334e93721e4a9d2e769..b1f1bf0e3f4e44c46ee3371f9102f79d6aea9d85 100644 (file)
@@ -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) {