backends: pass error logger to backends

This commit is contained in:
Michael Eischer
2025-09-14 16:13:21 +02:00
parent 13f743e26b
commit 4dc71f24c5
31 changed files with 96 additions and 96 deletions

View File

@@ -87,7 +87,7 @@ func TestLoadRawBrokenWithCache(t *testing.T) {
c := cache.TestNewCache(t)
repo, err := repository.New(b, repository.Options{})
rtest.OK(t, err)
repo.UseCache(c)
repo.UseCache(c, t.Logf)
data := rtest.Random(23, 10*KiB)
id := restic.Hash(data)

View File

@@ -161,13 +161,13 @@ func (r *Repository) packSize() uint {
}
// UseCache replaces the backend with the wrapped cache.
func (r *Repository) UseCache(c *cache.Cache) {
func (r *Repository) UseCache(c *cache.Cache, errorLog func(string, ...interface{})) {
if c == nil {
return
}
debug.Log("using cache")
r.cache = c
r.be = c.Wrap(r.be)
r.be = c.Wrap(r.be, errorLog)
}
func (r *Repository) Cache() *cache.Cache {

View File

@@ -207,7 +207,7 @@ func TestLoadBlobBroken(t *testing.T) {
// setup cache after saving the blob to make sure that the damageOnceBackend damages the cached data
c := cache.TestNewCache(t)
repo.UseCache(c)
repo.UseCache(c, t.Logf)
data, err := repo.LoadBlob(context.TODO(), restic.TreeBlob, id, nil)
rtest.OK(t, err)
@@ -355,7 +355,7 @@ func TestRepositoryLoadUnpackedRetryBroken(t *testing.T) {
repodir, cleanup := rtest.Env(t, repoFixture)
defer cleanup()
be, err := local.Open(context.TODO(), local.Config{Path: repodir, Connections: 2})
be, err := local.Open(context.TODO(), local.Config{Path: repodir, Connections: 2}, t.Logf)
rtest.OK(t, err)
repo := repository.TestOpenBackend(t, &damageOnceBackend{Backend: be})
@@ -446,7 +446,7 @@ func TestListPack(t *testing.T) {
// setup cache after saving the blob to make sure that the damageOnceBackend damages the cached data
c := cache.TestNewCache(t)
repo.UseCache(c)
repo.UseCache(c, t.Logf)
// Forcibly cache pack file
packID := repo.LookupBlob(restic.TreeBlob, id)[0].PackID

View File

@@ -91,7 +91,7 @@ func TestRepositoryWithVersion(t testing.TB, version uint) (*Repository, restic.
if dir != "" {
_, err := os.Stat(dir)
if err != nil {
lbe, err := local.Create(context.TODO(), local.Config{Path: dir})
lbe, err := local.Create(context.TODO(), local.Config{Path: dir}, t.Logf)
if err != nil {
t.Fatalf("error creating local backend at %v: %v", dir, err)
}
@@ -115,7 +115,7 @@ func TestFromFixture(t testing.TB, repoFixture string) (*Repository, backend.Bac
// TestOpenLocal opens a local repository.
func TestOpenLocal(t testing.TB, dir string) (*Repository, backend.Backend) {
var be backend.Backend
be, err := local.Open(context.TODO(), local.Config{Path: dir, Connections: 2})
be, err := local.Open(context.TODO(), local.Config{Path: dir, Connections: 2}, t.Logf)
if err != nil {
t.Fatal(err)
}