b2: Add pagination for List()
This commit is contained in:
parent
3b6a580b32
commit
835ba16c27
1 changed files with 13 additions and 4 deletions
|
@ -19,10 +19,13 @@ type b2Backend struct {
|
||||||
client *b2.Client
|
client *b2.Client
|
||||||
bucket *b2.Bucket
|
bucket *b2.Bucket
|
||||||
cfg Config
|
cfg Config
|
||||||
|
listMaxItems int
|
||||||
backend.Layout
|
backend.Layout
|
||||||
sem *backend.Semaphore
|
sem *backend.Semaphore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultListMaxItems = 1000
|
||||||
|
|
||||||
// ensure statically that *b2Backend implements restic.Backend.
|
// ensure statically that *b2Backend implements restic.Backend.
|
||||||
var _ restic.Backend = &b2Backend{}
|
var _ restic.Backend = &b2Backend{}
|
||||||
|
|
||||||
|
@ -121,6 +124,11 @@ func Create(cfg Config) (restic.Backend, error) {
|
||||||
return be, nil
|
return be, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetListMaxItems sets the number of list items to load per request.
|
||||||
|
func (be *b2Backend) SetListMaxItems(i int) {
|
||||||
|
be.listMaxItems = i
|
||||||
|
}
|
||||||
|
|
||||||
// Location returns the location for the backend.
|
// Location returns the location for the backend.
|
||||||
func (be *b2Backend) Location() string {
|
func (be *b2Backend) Location() string {
|
||||||
return be.cfg.Bucket
|
return be.cfg.Bucket
|
||||||
|
@ -307,10 +315,11 @@ func (be *b2Backend) List(ctx context.Context, t restic.FileType) <-chan string
|
||||||
cur := &b2.Cursor{Prefix: prefix}
|
cur := &b2.Cursor{Prefix: prefix}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
objs, c, err := be.bucket.ListCurrentObjects(ctx, 1000, cur)
|
objs, c, err := be.bucket.ListCurrentObjects(ctx, be.listMaxItems, cur)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
debug.Log("returned %v items", len(objs))
|
||||||
for _, obj := range objs {
|
for _, obj := range objs {
|
||||||
// Skip objects returned that do not have the specified prefix.
|
// Skip objects returned that do not have the specified prefix.
|
||||||
if !strings.HasPrefix(obj.Name(), prefix) {
|
if !strings.HasPrefix(obj.Name(), prefix) {
|
||||||
|
|
Loading…
Reference in a new issue