From d9bba67d1812c1cf754bf07640c60ad13d373174 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 25 Aug 2016 21:43:43 +0100 Subject: [PATCH] b2: return error when we try to create a bucket which someone else owns #645 --- b2/b2.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/b2/b2.go b/b2/b2.go index 05cf0e8b3..c262a4791 100644 --- a/b2/b2.go +++ b/b2/b2.go @@ -695,7 +695,16 @@ func (f *Fs) Mkdir() error { if err != nil { if apiErr, ok := err.(*api.Error); ok { if apiErr.Code == "duplicate_bucket_name" { - return nil + // Check this is our bucket - buckets are globally unique and this + // might be someone elses. + _, getBucketErr := f.getBucketID() + if getBucketErr == nil { + // found so it is our bucket + return nil + } + if getBucketErr != fs.ErrorDirNotFound { + fs.Debug(f, "Error checking bucket exists: %v", getBucketErr) + } } } return errors.Wrap(err, "failed to create bucket")