Fix infinite loop when the fs fails. Closes #1164

This commit is contained in:
Deluan 2021-07-16 09:38:58 -04:00
parent b0fc684cb6
commit eb8ffc6f76
1 changed files with 16 additions and 20 deletions

View File

@ -25,26 +25,6 @@ type (
walkResults = chan dirStats
)
func fullReadDir(name string) ([]os.DirEntry, error) {
f, err := os.Open(name)
if err != nil {
return nil, err
}
defer f.Close()
var allDirs []os.DirEntry
for {
dirs, err := f.ReadDir(-1)
allDirs = append(allDirs, dirs...)
if err == nil {
break
}
log.Warn("Skipping DirEntry", err)
}
sort.Slice(allDirs, func(i, j int) bool { return allDirs[i].Name() < allDirs[j].Name() })
return allDirs, nil
}
func walkDirTree(ctx context.Context, rootFolder string, results walkResults) error {
err := walkFolder(ctx, rootFolder, rootFolder, results)
if err != nil {
@ -120,6 +100,22 @@ func loadDir(ctx context.Context, dirPath string) ([]string, *dirStats, error) {
return children, stats, nil
}
func fullReadDir(name string) ([]os.DirEntry, error) {
f, err := os.Open(name)
if err != nil {
return nil, err
}
defer f.Close()
dirs, err := f.ReadDir(-1)
if err != nil {
log.Warn("Skipping DirEntry", err)
return nil, nil
}
sort.Slice(dirs, func(i, j int) bool { return dirs[i].Name() < dirs[j].Name() })
return dirs, nil
}
// isDirOrSymlinkToDir returns true if and only if the dirEnt represents a file
// system directory, or a symbolic link to a directory. Note that if the dirEnt
// is not a directory but is a symbolic link, this method will resolve by