2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-22 21:05:10 +00:00

Don't recurse in local backend's List if not required

Due to the return if !isFile, the IsDir branch in List was never taken
and subdirectories were traversed recursively.

Also replaced isFile by an IsRegular check, which has been equivalent
since Go 1.12 (golang/go@a2a3dd00c9).
This commit is contained in:
greatroar 2020-11-06 20:04:52 +01:00
parent 636b2f2e94
commit a2d4209322

View File

@ -220,32 +220,27 @@ func (b *Local) Remove(ctx context.Context, h restic.Handle) error {
return fs.Remove(fn)
}
func isFile(fi os.FileInfo) bool {
return fi.Mode()&(os.ModeType|os.ModeCharDevice) == 0
}
// List runs fn for each file in the backend which has the type t. When an
// error occurs (or fn returns an error), List stops and returns it.
func (b *Local) List(ctx context.Context, t restic.FileType, fn func(restic.FileInfo) error) error {
debug.Log("List %v", t)
basedir, subdirs := b.Basedir(t)
atBasedir := true
err := fs.Walk(basedir, func(path string, fi os.FileInfo, err error) error {
debug.Log("walk on %v\n", path)
if err != nil {
return err
}
if path == basedir {
switch {
case atBasedir: // Skip basedir itself.
atBasedir = false
return nil
}
if !isFile(fi) {
return nil
}
if fi.IsDir() && !subdirs {
case fi.IsDir() && !subdirs:
return filepath.SkipDir
case !fi.Mode().IsRegular():
return nil
}
debug.Log("send %v\n", filepath.Base(path))