From 0cb5c4aa730118fbf0c25f3636abbcc4c36e8452 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 5 Apr 2018 15:17:53 +0100 Subject: [PATCH] gcs: detect bucket presence by listing it - fixes #2193 Doing it like this enables the use of a service account that only has the "Storage Object Admin" role. --- backend/googlecloudstorage/googlecloudstorage.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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