2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-22 12:55:18 +00:00

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)
}
}()