Merge duplicated readdir functionality

internal/archiver.readdir and internal/fs.ReadDir were unused.

internal/fs.ReadDirNames and internal/archiver.readdirnames were doing
nearly the same thing, except one sorted its output and opened with
fs.O_NOFOLLOW. Both were only used in internal/archiver.
This commit is contained in:
greatroar 2020-02-17 09:22:32 +01:00
parent 2f8aa2ce30
commit 79b882e901
4 changed files with 15 additions and 91 deletions

View file

@ -4,6 +4,7 @@ import (
"context"
"os"
"path/filepath"
"sort"
"github.com/restic/restic/internal/fs"
)
@ -86,10 +87,11 @@ func (s *Scanner) scan(ctx context.Context, stats ScanStats, target string) (Sca
stats.Files++
stats.Bytes += uint64(fi.Size())
case fi.Mode().IsDir():
names, err := readdirnames(s.FS, target)
names, err := readdirnames(s.FS, target, fs.O_NOFOLLOW)
if err != nil {
return stats, s.Error(target, fi, err)
}
sort.Strings(names)
for _, name := range names {
stats, err = s.scan(ctx, stats, filepath.Join(target, name))