b2: fix listing all buckets when not needed
Before this change the b2 backend listed all the buckets to turn a single bucket name into an ID. However in July 26, 2018 a parameter was added to the list buckets API to make listing all the buckets unecessary. This code sets the bucketName parameter so that only the results for the desired bucket are returned.
This commit is contained in:
parent
55c12c9a2d
commit
4ef30db209
1 changed files with 7 additions and 4 deletions
|
@ -824,7 +824,7 @@ func (f *Fs) listDir(ctx context.Context, bucket, directory, prefix string, addB
|
||||||
|
|
||||||
// listBuckets returns all the buckets to out
|
// listBuckets returns all the buckets to out
|
||||||
func (f *Fs) listBuckets(ctx context.Context) (entries fs.DirEntries, err error) {
|
func (f *Fs) listBuckets(ctx context.Context) (entries fs.DirEntries, err error) {
|
||||||
err = f.listBucketsToFn(ctx, func(bucket *api.Bucket) error {
|
err = f.listBucketsToFn(ctx, "", func(bucket *api.Bucket) error {
|
||||||
d := fs.NewDir(bucket.Name, time.Time{})
|
d := fs.NewDir(bucket.Name, time.Time{})
|
||||||
entries = append(entries, d)
|
entries = append(entries, d)
|
||||||
return nil
|
return nil
|
||||||
|
@ -917,11 +917,14 @@ func (f *Fs) ListR(ctx context.Context, dir string, callback fs.ListRCallback) (
|
||||||
type listBucketFn func(*api.Bucket) error
|
type listBucketFn func(*api.Bucket) error
|
||||||
|
|
||||||
// listBucketsToFn lists the buckets to the function supplied
|
// listBucketsToFn lists the buckets to the function supplied
|
||||||
func (f *Fs) listBucketsToFn(ctx context.Context, fn listBucketFn) error {
|
func (f *Fs) listBucketsToFn(ctx context.Context, bucketName string, fn listBucketFn) error {
|
||||||
var account = api.ListBucketsRequest{
|
var account = api.ListBucketsRequest{
|
||||||
AccountID: f.info.AccountID,
|
AccountID: f.info.AccountID,
|
||||||
BucketID: f.info.Allowed.BucketID,
|
BucketID: f.info.Allowed.BucketID,
|
||||||
}
|
}
|
||||||
|
if bucketName != "" && account.BucketID == "" {
|
||||||
|
account.BucketName = f.opt.Enc.FromStandardName(bucketName)
|
||||||
|
}
|
||||||
|
|
||||||
var response api.ListBucketsResponse
|
var response api.ListBucketsResponse
|
||||||
opts := rest.Opts{
|
opts := rest.Opts{
|
||||||
|
@ -967,7 +970,7 @@ func (f *Fs) getbucketType(ctx context.Context, bucket string) (bucketType strin
|
||||||
if bucketType != "" {
|
if bucketType != "" {
|
||||||
return bucketType, nil
|
return bucketType, nil
|
||||||
}
|
}
|
||||||
err = f.listBucketsToFn(ctx, func(bucket *api.Bucket) error {
|
err = f.listBucketsToFn(ctx, bucket, func(bucket *api.Bucket) error {
|
||||||
// listBucketsToFn reads bucket Types
|
// listBucketsToFn reads bucket Types
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
@ -1002,7 +1005,7 @@ func (f *Fs) getBucketID(ctx context.Context, bucket string) (bucketID string, e
|
||||||
if bucketID != "" {
|
if bucketID != "" {
|
||||||
return bucketID, nil
|
return bucketID, nil
|
||||||
}
|
}
|
||||||
err = f.listBucketsToFn(ctx, func(bucket *api.Bucket) error {
|
err = f.listBucketsToFn(ctx, bucket, func(bucket *api.Bucket) error {
|
||||||
// listBucketsToFn sets IDs
|
// listBucketsToFn sets IDs
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue