2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-23 19:38:57 +00:00

cache: correctly ignore files whose filename is no ID

this can for example be the case for temporary files created by the
backend implementation.
This commit is contained in:
Michael Eischer 2024-08-29 16:32:15 +02:00
parent 1931beab8e
commit 8eff4e0e5c
2 changed files with 19 additions and 3 deletions

View File

@ -231,9 +231,8 @@ func (b *Backend) List(ctx context.Context, t backend.FileType, fn func(f backen
wrapFn := func(f backend.FileInfo) error {
id, err := restic.ParseID(f.Name)
if err != nil {
// returning error here since, if we cannot parse the ID, the file
// is invalid and the list must exit.
return err
// ignore files with invalid name
return nil
}
ids.Insert(id)

View File

@ -296,3 +296,20 @@ func TestAutomaticCacheClear(t *testing.T) {
t.Errorf("cache doesn't have file2 after list")
}
}
func TestAutomaticCacheClearInvalidFilename(t *testing.T) {
be := mem.New()
c := TestNewCache(t)
data := test.Random(rand.Int(), 42)
h := backend.Handle{
Type: backend.IndexFile,
Name: "tmp12345",
}
save(t, be, h, data)
wbe := c.Wrap(be)
// list all files in the backend
list(t, wbe, func(_ backend.FileInfo) error { return nil })
}