improve dir reading

Signed-off-by: kim (grufwub) <grufwub@gmail.com>
development
kim (grufwub) 4 years ago
parent a6108587cd
commit f8c9c738ab

@ -89,18 +89,24 @@ func ScanFile(file *os.File, iterator func(string) bool) *errors.Error {
// ScanDirectory reads the contents of a directory and performs the iterator function on each os.FileInfo entry returned
func ScanDirectory(dir *os.File, p *Path, iterator func(os.FileInfo, *Path)) *errors.Error {
dirList, err := dir.Readdir(-1)
nameList, err := dir.Readdirnames(-1)
if err != nil {
return errors.WrapError(DirectoryReadErr, err)
}
// Sort by name
sort.Sort(byName(dirList))
sort.Strings(nameList)
// Walk through the directory list using supplied iterator function
for _, info := range dirList {
for _, name := range nameList {
// Make new Path object
fp := p.JoinPath(info.Name())
fp := p.JoinPath(name)
// Get stat
stat, err := StatFile(fp)
if err != nil {
return err
}
// Skip restricted files
if IsRestrictedPath(fp) || IsHiddenPath(fp) || WithinCGIDir(fp) {
@ -108,7 +114,7 @@ func ScanDirectory(dir *os.File, p *Path, iterator func(os.FileInfo, *Path)) *er
}
// Perform iterator
iterator(info, p.JoinPath(info.Name()))
iterator(stat, fp)
}
return nil

Loading…
Cancel
Save