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.
This commit is contained in:
Michael Eischer
2026-06-05 13:19:29 +02:00
parent c967d634be
commit 8118963d6e
+1 -14
View File
@@ -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())