gs: implement pagination

This commit is contained in:
Alexander Neumann 2017-09-17 11:08:51 +02:00
parent c35518a865
commit 40edf00182

View file

@ -298,22 +298,33 @@ func (be *Backend) List(ctx context.Context, t restic.FileType) <-chan string {
go func() {
defer close(ch)
obj, err := be.service.Objects.List(be.bucketName).Prefix(prefix).Do()
if err != nil {
return
}
for _, item := range obj.Items {
m := strings.TrimPrefix(item.Name, prefix)
if m == "" {
continue
}
select {
case ch <- path.Base(m):
case <-ctx.Done():
listReq := be.service.Objects.List(be.bucketName).Prefix(prefix)
for {
obj, err := listReq.Do()
if err != nil {
fmt.Fprintf(os.Stderr, "error listing %v: %v\n", prefix, err)
return
}
debug.Log("returned %v items", len(obj.Items))
for _, item := range obj.Items {
m := strings.TrimPrefix(item.Name, prefix)
if m == "" {
continue
}
select {
case ch <- path.Base(m):
case <-ctx.Done():
return
}
}
if obj.NextPageToken == "" {
break
}
listReq.PageToken(obj.NextPageToken)
}
}()