diff --git a/internal/archiver/archiver_test.go b/internal/archiver/archiver_test.go index e99a6c90e..38641cff3 100644 --- a/internal/archiver/archiver_test.go +++ b/internal/archiver/archiver_test.go @@ -91,7 +91,7 @@ func saveFile(t testing.TB, repo restic.Repository, filename string, filesystem t.Fatal(err) } - err = repo.Flush(ctx) + err = repo.Flush(context.Background()) if err != nil { t.Fatal(err) } @@ -839,6 +839,7 @@ func TestArchiverSaveDir(t *testing.T) { t.Errorf("wrong stats returned in TreeBlobs, want > 0, got %d", stats.TreeBlobs) } + ctx = context.Background() node.Name = targetNodeName tree := &restic.Tree{Nodes: []*restic.Node{node}} treeID, err := repo.SaveTree(ctx, tree) @@ -934,7 +935,7 @@ func TestArchiverSaveDirIncremental(t *testing.T) { t.Logf("node subtree %v", node.Subtree) - err = repo.Flush(ctx) + err = repo.Flush(context.Background()) if err != nil { t.Fatal(err) } @@ -1091,6 +1092,7 @@ func TestArchiverSaveTree(t *testing.T) { t.Fatal(err) } + ctx = context.Background() err = repo.Flush(ctx) if err != nil { t.Fatal(err) diff --git a/internal/backend/mem/mem_backend.go b/internal/backend/mem/mem_backend.go index a8244be43..fc7196f0b 100644 --- a/internal/backend/mem/mem_backend.go +++ b/internal/backend/mem/mem_backend.go @@ -47,10 +47,10 @@ func (be *MemoryBackend) Test(ctx context.Context, h restic.Handle) (bool, error debug.Log("Test %v", h) if _, ok := be.data[h]; ok { - return true, nil + return true, ctx.Err() } - return false, nil + return false, ctx.Err() } // IsNotExist returns true if the file does not exist. @@ -83,7 +83,7 @@ func (be *MemoryBackend) Save(ctx context.Context, h restic.Handle, rd restic.Re be.data[h] = buf debug.Log("saved %v bytes at %v", len(buf), h) - return nil + return ctx.Err() } // Load runs fn with a reader that yields the contents of the file at h at the @@ -124,7 +124,7 @@ func (be *MemoryBackend) openReader(ctx context.Context, h restic.Handle, length buf = buf[:length] } - return ioutil.NopCloser(bytes.NewReader(buf)), nil + return ioutil.NopCloser(bytes.NewReader(buf)), ctx.Err() } // Stat returns information about a file in the backend. @@ -147,7 +147,7 @@ func (be *MemoryBackend) Stat(ctx context.Context, h restic.Handle) (restic.File return restic.FileInfo{}, errNotFound } - return restic.FileInfo{Size: int64(len(e)), Name: h.Name}, nil + return restic.FileInfo{Size: int64(len(e)), Name: h.Name}, ctx.Err() } // Remove deletes a file from the backend. @@ -163,7 +163,7 @@ func (be *MemoryBackend) Remove(ctx context.Context, h restic.Handle) error { delete(be.data, h) - return nil + return ctx.Err() } // List returns a channel which yields entries from the backend. @@ -213,6 +213,10 @@ func (be *MemoryBackend) Delete(ctx context.Context) error { be.m.Lock() defer be.m.Unlock() + if ctx.Err() != nil { + return ctx.Err() + } + be.data = make(memMap) return nil }