mirror of
https://github.com/restic/restic.git
synced 2025-08-23 14:57:37 +00:00
replace ad-hoc context.TODO() with gopts.ctx, so that cancellation
can properly trickle down from cmd_*. gh-1434
This commit is contained in:
@@ -89,7 +89,7 @@ func (r *packerManager) insertPacker(p *Packer) {
|
||||
}
|
||||
|
||||
// savePacker stores p in the backend.
|
||||
func (r *Repository) savePacker(t restic.BlobType, p *Packer) error {
|
||||
func (r *Repository) savePacker(ctx context.Context, t restic.BlobType, p *Packer) error {
|
||||
debug.Log("save packer for %v with %d blobs (%d bytes)\n", t, p.Packer.Count(), p.Packer.Size())
|
||||
_, err := p.Packer.Finalize()
|
||||
if err != nil {
|
||||
@@ -104,7 +104,7 @@ func (r *Repository) savePacker(t restic.BlobType, p *Packer) error {
|
||||
id := restic.IDFromHash(p.hw.Sum(nil))
|
||||
h := restic.Handle{Type: restic.DataFile, Name: id.String()}
|
||||
|
||||
err = r.be.Save(context.TODO(), h, p.tmpfile)
|
||||
err = r.be.Save(ctx, h, p.tmpfile)
|
||||
if err != nil {
|
||||
debug.Log("Save(%v) error: %v", h, err)
|
||||
return err
|
||||
|
@@ -126,7 +126,7 @@ func Repack(ctx context.Context, repo restic.Repository, packs restic.IDSet, kee
|
||||
}
|
||||
}
|
||||
|
||||
if err := repo.Flush(); err != nil {
|
||||
if err := repo.Flush(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@@ -55,13 +55,13 @@ func createRandomBlobs(t testing.TB, repo restic.Repository, blobs int, pData fl
|
||||
}
|
||||
|
||||
if rand.Float32() < 0.2 {
|
||||
if err = repo.Flush(); err != nil {
|
||||
if err = repo.Flush(context.Background()); err != nil {
|
||||
t.Fatalf("repo.Flush() returned error %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := repo.Flush(); err != nil {
|
||||
if err := repo.Flush(context.Background()); err != nil {
|
||||
t.Fatalf("repo.Flush() returned error %v", err)
|
||||
}
|
||||
}
|
||||
|
@@ -250,7 +250,7 @@ func (r *Repository) SaveAndEncrypt(ctx context.Context, t restic.BlobType, data
|
||||
}
|
||||
|
||||
// else write the pack to the backend
|
||||
return *id, r.savePacker(t, packer)
|
||||
return *id, r.savePacker(ctx, t, packer)
|
||||
}
|
||||
|
||||
// SaveJSONUnpacked serialises item as JSON and encrypts and saves it in the
|
||||
@@ -289,7 +289,7 @@ func (r *Repository) SaveUnpacked(ctx context.Context, t restic.FileType, p []by
|
||||
}
|
||||
|
||||
// Flush saves all remaining packs.
|
||||
func (r *Repository) Flush() error {
|
||||
func (r *Repository) Flush(ctx context.Context) error {
|
||||
pms := []struct {
|
||||
t restic.BlobType
|
||||
pm *packerManager
|
||||
@@ -303,7 +303,7 @@ func (r *Repository) Flush() error {
|
||||
|
||||
debug.Log("manually flushing %d packs", len(p.pm.packers))
|
||||
for _, packer := range p.pm.packers {
|
||||
err := r.savePacker(p.t, packer)
|
||||
err := r.savePacker(ctx, p.t, packer)
|
||||
if err != nil {
|
||||
p.pm.pm.Unlock()
|
||||
return err
|
||||
|
@@ -37,7 +37,7 @@ func TestSave(t *testing.T) {
|
||||
|
||||
rtest.Equals(t, id, sid)
|
||||
|
||||
rtest.OK(t, repo.Flush())
|
||||
rtest.OK(t, repo.Flush(context.Background()))
|
||||
// rtest.OK(t, repo.SaveIndex())
|
||||
|
||||
// read back
|
||||
@@ -72,7 +72,7 @@ func TestSaveFrom(t *testing.T) {
|
||||
rtest.OK(t, err)
|
||||
rtest.Equals(t, id, id2)
|
||||
|
||||
rtest.OK(t, repo.Flush())
|
||||
rtest.OK(t, repo.Flush(context.Background()))
|
||||
|
||||
// read back
|
||||
buf := restic.NewBlobBuffer(size)
|
||||
@@ -122,7 +122,7 @@ func TestLoadTree(t *testing.T) {
|
||||
|
||||
// archive a few files
|
||||
sn := archiver.TestSnapshot(t, repo, rtest.BenchArchiveDirectory, nil)
|
||||
rtest.OK(t, repo.Flush())
|
||||
rtest.OK(t, repo.Flush(context.Background()))
|
||||
|
||||
_, err := repo.LoadTree(context.TODO(), *sn.Tree)
|
||||
rtest.OK(t, err)
|
||||
@@ -138,7 +138,7 @@ func BenchmarkLoadTree(t *testing.B) {
|
||||
|
||||
// archive a few files
|
||||
sn := archiver.TestSnapshot(t, repo, rtest.BenchArchiveDirectory, nil)
|
||||
rtest.OK(t, repo.Flush())
|
||||
rtest.OK(t, repo.Flush(context.Background()))
|
||||
|
||||
t.ResetTimer()
|
||||
|
||||
@@ -159,7 +159,7 @@ func TestLoadBlob(t *testing.T) {
|
||||
|
||||
id, err := repo.SaveBlob(context.TODO(), restic.DataBlob, buf, restic.ID{})
|
||||
rtest.OK(t, err)
|
||||
rtest.OK(t, repo.Flush())
|
||||
rtest.OK(t, repo.Flush(context.Background()))
|
||||
|
||||
// first, test with buffers that are too small
|
||||
for _, testlength := range []int{length - 20, length, restic.CiphertextLength(length) - 1} {
|
||||
@@ -204,7 +204,7 @@ func BenchmarkLoadBlob(b *testing.B) {
|
||||
|
||||
id, err := repo.SaveBlob(context.TODO(), restic.DataBlob, buf, restic.ID{})
|
||||
rtest.OK(b, err)
|
||||
rtest.OK(b, repo.Flush())
|
||||
rtest.OK(b, repo.Flush(context.Background()))
|
||||
|
||||
b.ResetTimer()
|
||||
b.SetBytes(int64(length))
|
||||
@@ -352,7 +352,7 @@ func TestRepositoryIncrementalIndex(t *testing.T) {
|
||||
// add 3 packs, write intermediate index
|
||||
for i := 0; i < 3; i++ {
|
||||
saveRandomDataBlobs(t, repo, 5, 1<<15)
|
||||
rtest.OK(t, repo.Flush())
|
||||
rtest.OK(t, repo.Flush(context.Background()))
|
||||
}
|
||||
|
||||
rtest.OK(t, repo.SaveFullIndex(context.TODO()))
|
||||
@@ -361,7 +361,7 @@ func TestRepositoryIncrementalIndex(t *testing.T) {
|
||||
// add another 5 packs
|
||||
for i := 0; i < 5; i++ {
|
||||
saveRandomDataBlobs(t, repo, 5, 1<<15)
|
||||
rtest.OK(t, repo.Flush())
|
||||
rtest.OK(t, repo.Flush(context.Background()))
|
||||
}
|
||||
|
||||
// save final index
|
||||
|
Reference in New Issue
Block a user