Skip to content

Commit

Permalink
Bump restic
Browse files Browse the repository at this point in the history
Upstream ref: 45ba456291b46d6cb4e03511aa2a101f9a78405b
  • Loading branch information
rubiojr committed Nov 15, 2020
1 parent 4758de2 commit a4960cd
Show file tree
Hide file tree
Showing 37 changed files with 570 additions and 282 deletions.
16 changes: 10 additions & 6 deletions backend/mem/mem_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 7 additions & 5 deletions backend/s3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ type Config struct {
Layout string `option:"layout" help:"use this backend layout (default: auto-detect)"`
StorageClass string `option:"storage-class" help:"set S3 storage class (STANDARD, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING or REDUCED_REDUNDANCY)"`

Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 5)"`
MaxRetries uint `option:"retries" help:"set the number of retries attempted"`
Region string `option:"region" help:"set region"`
BucketLookup string `option:"bucket-lookup" help:"bucket lookup style: 'auto', 'dns', or 'path'."`
Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 5)"`
MaxRetries uint `option:"retries" help:"set the number of retries attempted"`
Region string `option:"region" help:"set region"`
BucketLookup string `option:"bucket-lookup" help:"bucket lookup style: 'auto', 'dns', or 'path'"`
ListObjectsV1 bool `option:"list-objects-v1" help:"use deprecated V1 api for ListObjects calls"`
}

// NewConfig returns a new Config with the default values filled in.
func NewConfig() Config {
return Config{
Connections: 5,
Connections: 5,
ListObjectsV1: false,
}
}

Expand Down
6 changes: 6 additions & 0 deletions backend/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,12 @@ func (be *Backend) ReadDir(ctx context.Context, dir string) (list []os.FileInfo,
ctx, cancel := context.WithCancel(ctx)
defer cancel()

debug.Log("using ListObjectsV1(%v)", be.cfg.ListObjectsV1)

for obj := range be.client.ListObjects(ctx, be.cfg.Bucket, minio.ListObjectsOptions{
Prefix: dir,
Recursive: false,
UseV1: be.cfg.ListObjectsV1,
}) {
if obj.Err != nil {
return nil, err
Expand Down Expand Up @@ -427,12 +430,15 @@ func (be *Backend) List(ctx context.Context, t restic.FileType, fn func(restic.F
ctx, cancel := context.WithCancel(ctx)
defer cancel()

debug.Log("using ListObjectsV1(%v)", be.cfg.ListObjectsV1)

// NB: unfortunately we can't protect this with be.sem.GetToken() here.
// Doing so would enable a deadlock situation (gh-1399), as ListObjects()
// starts its own goroutine and returns results via a channel.
listresp := be.client.ListObjects(ctx, be.cfg.Bucket, minio.ListObjectsOptions{
Prefix: prefix,
Recursive: recursive,
UseV1: be.cfg.ListObjectsV1,
})

for obj := range listresp {
Expand Down
2 changes: 1 addition & 1 deletion internal/archiver/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ func resolveRelativeTargets(filesys fs.FS, targets []string) ([]string, error) {

// SnapshotOptions collect attributes for a new snapshot.
type SnapshotOptions struct {
Tags []string
Tags restic.TagList
Hostname string
Excludes []string
Time time.Time
Expand Down
6 changes: 4 additions & 2 deletions internal/archiver/archiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit a4960cd

Please sign in to comment.