Merge pull request #3068 from aawsome/context-mem-backend

Return context error in mem backend
This commit is contained in:
MichaelEischer 2020-11-08 12:24:12 +01:00 committed by GitHub
commit 1758da855f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -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)

View File

@ -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
}