Use Readdirnames to reduce number of stats we're doing.

This commit is contained in:
Tom Wilkie
2015-12-09 17:42:36 +00:00
parent efecea3714
commit 1fcd079563
4 changed files with 47 additions and 10 deletions

View File

@@ -10,6 +10,7 @@ import (
// Interface is the filesystem interface type.
type Interface interface {
ReadDir(string) ([]os.FileInfo, error)
ReadDirNames(string) ([]string, error)
ReadFile(string) ([]byte, error)
Lstat(string, *syscall.Stat_t) error
Stat(string, *syscall.Stat_t) error
@@ -25,6 +26,15 @@ func (realFS) ReadDir(path string) ([]os.FileInfo, error) {
return ioutil.ReadDir(path)
}
func (realFS) ReadDirNames(path string) ([]string, error) {
fh, err := os.Open(path)
if err != nil {
return nil, err
}
defer fh.Close()
return fh.Readdirnames(-1)
}
func (realFS) ReadFile(path string) ([]byte, error) {
return ioutil.ReadFile(path)
}
@@ -48,6 +58,11 @@ func ReadDir(path string) ([]os.FileInfo, error) {
return fs.ReadDir(path)
}
// ReadDirNames see os.File.ReadDirNames
func ReadDirNames(path string) ([]string, error) {
return fs.ReadDirNames(path)
}
// ReadFile see ioutil.ReadFile
func ReadFile(path string) ([]byte, error) {
return fs.ReadFile(path)