mirror of
https://github.com/restic/restic.git
synced 2024-12-23 00:07:25 +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:
parent
8eb6a5805b
commit
a293fd9aef
2 changed files with 18 additions and 3 deletions
8
changelog/unreleased/issue-3302
Normal file
8
changelog/unreleased/issue-3302
Normal 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
|
|
@ -245,7 +245,7 @@ func (b *Local) List(ctx context.Context, t restic.FileType, fn func(restic.File
|
||||||
if subdirs {
|
if subdirs {
|
||||||
err = visitDirs(ctx, basedir, fn)
|
err = visitDirs(ctx, basedir, fn)
|
||||||
} else {
|
} else {
|
||||||
err = visitFiles(ctx, basedir, fn)
|
err = visitFiles(ctx, basedir, fn, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.IsNotExist(err) {
|
if b.IsNotExist(err) {
|
||||||
|
@ -279,7 +279,7 @@ func visitDirs(ctx context.Context, dir string, fn func(restic.FileInfo) error)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range sub {
|
for _, f := range sub {
|
||||||
err = visitFiles(ctx, filepath.Join(dir, f), fn)
|
err = visitFiles(ctx, filepath.Join(dir, f), fn, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -287,12 +287,19 @@ func visitDirs(ctx context.Context, dir string, fn func(restic.FileInfo) error)
|
||||||
return ctx.Err()
|
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)
|
d, err := fs.Open(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ignoreNotADirectory {
|
||||||
|
fi, err := d.Stat()
|
||||||
|
if err != nil || !fi.IsDir() {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub, err := d.Readdir(-1)
|
sub, err := d.Readdir(-1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// ignore subsequent errors
|
// ignore subsequent errors
|
||||||
|
|
Loading…
Reference in a new issue