2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 02:48:55 +00:00

local: Ignore files in intermediate folders

For example the data folder of a repository might contain hidden files
which caused list operations to fail.
This commit is contained in:
Michael Eischer 2021-02-27 00:02:13 +01:00
parent 8eb6a5805b
commit a293fd9aef
2 changed files with 18 additions and 3 deletions

View File

@ -0,0 +1,8 @@
Bugfix: Fix `fdopendir: not a directory` error for local backend
The `check`, `list packs`, `prune` and `rebuild-index` commands failed
for the local backend when the `data` folder in the repository contained
files. This has been fixed.
https://github.com/restic/restic/issues/3302
https://github.com/restic/restic/pull/3308

View File

@ -245,7 +245,7 @@ func (b *Local) List(ctx context.Context, t restic.FileType, fn func(restic.File
if subdirs {
err = visitDirs(ctx, basedir, fn)
} else {
err = visitFiles(ctx, basedir, fn)
err = visitFiles(ctx, basedir, fn, false)
}
if b.IsNotExist(err) {
@ -279,7 +279,7 @@ func visitDirs(ctx context.Context, dir string, fn func(restic.FileInfo) error)
}
for _, f := range sub {
err = visitFiles(ctx, filepath.Join(dir, f), fn)
err = visitFiles(ctx, filepath.Join(dir, f), fn, true)
if err != nil {
return err
}
@ -287,12 +287,19 @@ func visitDirs(ctx context.Context, dir string, fn func(restic.FileInfo) error)
return ctx.Err()
}
func visitFiles(ctx context.Context, dir string, fn func(restic.FileInfo) error) error {
func visitFiles(ctx context.Context, dir string, fn func(restic.FileInfo) error, ignoreNotADirectory bool) error {
d, err := fs.Open(dir)
if err != nil {
return err
}
if ignoreNotADirectory {
fi, err := d.Stat()
if err != nil || !fi.IsDir() {
return err
}
}
sub, err := d.Readdir(-1)
if err != nil {
// ignore subsequent errors