Skip to content

Commit

Permalink
refactor: replace Readdir(-1) with ioutil.ReadDir
Browse files Browse the repository at this point in the history
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
  • Loading branch information
Juneezee committed Nov 27, 2022
1 parent ed0c4d0 commit cd99ed9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
11 changes: 4 additions & 7 deletions fsutil/finder/finder.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package finder

import (
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -248,17 +249,13 @@ func (f *FileFinder) findInDir(dirPath string) {
return // ignore I/O error
}

// opening
d, err := os.Open(dirPath)
// sort.Strings(names)
// names, _ := d.Readdirnames(-1)
stats, err := ioutil.ReadDir(dirPath)
if err != nil {
return // ignore I/O error
}

// sort.Strings(names)
// names, _ := d.Readdirnames(-1)
stats, _ := d.Readdir(-1)
_ = d.Close() // close dir.

for _, fi := range stats {
baseName := fi.Name()
fullPath := filepath.Join(dirPath, baseName)
Expand Down
13 changes: 6 additions & 7 deletions fsutil/info.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fsutil

import (
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -86,16 +87,14 @@ func FindInDir(dir string, handleFn HandleFunc, filters ...FilterFunc) (e error)
return // ignore I/O error
}

d, err := os.Open(dir)
if err != nil {
return // ignore I/O error
}
defer d.Close()

// names, _ := d.Readdirnames(-1)
// sort.Strings(names)

stats, _ := d.Readdir(-1)
stats, err := ioutil.ReadDir(dir)
if err != nil {
return
}

for _, fi := range stats {
baseName := fi.Name()
filePath := dir + "/" + baseName
Expand Down

0 comments on commit cd99ed9

Please sign in to comment.