Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

gcs: detect bucket presence by listing it - fixes #2193

Nick Craig-Wood0cb5c4aa7301
diff --git a/backend/googlecloudstorage/googlecloudstorage.go b/backend/googlecloudstorage/googlecloudstorage.go
index 7ca0ad24a..8358a37d5 100644
--- a/backend/googlecloudstorage/googlecloudstorage.go
+++ b/backend/googlecloudstorage/googlecloudstorage.go
@@ -608,7 +608,9 @@ func (f *Fs) Mkdir(dir string) error {
if f.bucketOK {
return nil
}
- _, err := f.svc.Buckets.Get(f.bucket).Do()
+ // List something from the bucket to see if it exists. Doing it like this enables the use of a
+ // service account that only has the "Storage Object Admin" role. See #2193 for details.
+ _, err := f.svc.Objects.List(f.bucket).MaxResults(1).Do()
if err == nil {
// Bucket already exists
f.bucketOK = true