Merge pull request #3308 from MichaelEischer/fix-not-a-directory

local: Ignore files in intermediate folders
This commit is contained in:
MichaelEischer 2021-02-27 15:34:36 +01:00 committed by GitHub
commit 4baebdc6f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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