forked from TrueCloudLab/restic
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:
parent
636b2f2e94
commit
a2d4209322
1 changed files with 7 additions and 12 deletions
|
@ -220,32 +220,27 @@ func (b *Local) Remove(ctx context.Context, h restic.Handle) error {
|
||||||
return fs.Remove(fn)
|
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
|
// 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.
|
// 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 {
|
func (b *Local) List(ctx context.Context, t restic.FileType, fn func(restic.FileInfo) error) error {
|
||||||
debug.Log("List %v", t)
|
debug.Log("List %v", t)
|
||||||
|
|
||||||
basedir, subdirs := b.Basedir(t)
|
basedir, subdirs := b.Basedir(t)
|
||||||
|
atBasedir := true
|
||||||
err := fs.Walk(basedir, func(path string, fi os.FileInfo, err error) error {
|
err := fs.Walk(basedir, func(path string, fi os.FileInfo, err error) error {
|
||||||
debug.Log("walk on %v\n", path)
|
debug.Log("walk on %v\n", path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if path == basedir {
|
switch {
|
||||||
|
case atBasedir: // Skip basedir itself.
|
||||||
|
atBasedir = false
|
||||||
return nil
|
return nil
|
||||||
}
|
case fi.IsDir() && !subdirs:
|
||||||
|
|
||||||
if !isFile(fi) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if fi.IsDir() && !subdirs {
|
|
||||||
return filepath.SkipDir
|
return filepath.SkipDir
|
||||||
|
case !fi.Mode().IsRegular():
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
debug.Log("send %v\n", filepath.Base(path))
|
debug.Log("send %v\n", filepath.Base(path))
|
||||||
|
|
Loading…
Reference in a new issue