From 1f4c9d280629f2afde9c6a294590f73962b37e83 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Thu, 29 Aug 2024 16:32:15 +0200 Subject: [PATCH] cache: correctly ignore files whose filename is no ID this can for example be the case for temporary files created by the backend implementation. --- internal/backend/cache/backend.go | 5 ++--- internal/backend/cache/backend_test.go | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/internal/backend/cache/backend.go b/internal/backend/cache/backend.go index 58b03dd38..3754266ba 100644 --- a/internal/backend/cache/backend.go +++ b/internal/backend/cache/backend.go @@ -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) diff --git a/internal/backend/cache/backend_test.go b/internal/backend/cache/backend_test.go index dca51c2bf..7f83e40cb 100644 --- a/internal/backend/cache/backend_test.go +++ b/internal/backend/cache/backend_test.go @@ -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 }) +}