From 8118963d6ecc5b75da8a2375a89d14c11e62b81f Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 5 Jun 2026 13:19:29 +0200 Subject: [PATCH] cache: remove dependency on crypto package for truncation checks The cache backend + repository can by now properly recover from damaged files stored in the cache. Thus, remove the legacy sanity check. --- internal/backend/cache/file.go | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/internal/backend/cache/file.go b/internal/backend/cache/file.go index 062d6ea3f..864f12ed6 100644 --- a/internal/backend/cache/file.go +++ b/internal/backend/cache/file.go @@ -10,7 +10,6 @@ import ( "github.com/pkg/errors" "github.com/restic/restic/internal/backend" "github.com/restic/restic/internal/backend/util" - "github.com/restic/restic/internal/crypto" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/restic" ) @@ -55,11 +54,6 @@ func (c *Cache) load(h backend.Handle, length int, offset int64) (io.ReadCloser, } size := fi.Size() - if size <= int64(crypto.CiphertextLength(0)) { - _ = f.Close() - return nil, true, errors.Errorf("cached file %v is truncated", h) - } - if size < offset+int64(length) { _ = f.Close() return nil, true, errors.Errorf("cached file %v is too short", h) @@ -102,20 +96,13 @@ func (c *Cache) save(h backend.Handle, rd io.Reader) error { return err } - n, err := io.Copy(f, rd) + _, err = io.Copy(f, rd) if err != nil { _ = f.Close() _ = os.Remove(f.Name()) return errors.Wrap(err, "Copy") } - if n <= int64(crypto.CiphertextLength(0)) { - _ = f.Close() - _ = os.Remove(f.Name()) - debug.Log("trying to cache truncated file %v, removing", h) - return nil - } - // Close, then rename. Windows doesn't like the reverse order. if err = f.Close(); err != nil { _ = os.Remove(f.Name())