mirror of
https://github.com/weaveworks/scope.git
synced 2026-05-06 01:08:03 +00:00
Use Readdirnames to reduce number of stats we're doing.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user