"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
s3: work around eventual consistency in bucket creation
Nick Craig-Wood54561fd2bcfe
diff --git a/fs/sync_test.go b/fs/sync_test.goindex 1764c9556..bc0b527bc 100644--- a/fs/sync_test.go+++ b/fs/sync_test.go@@ -715,6 +715,7 @@ func testServerSideMove(t *testing.T, r *Run, fremoteMove fs.Fs, withFilter bool// Purge the original before movingrequire.NoError(t, fs.Purge(r.fremote))+ fstest.CheckItems(t, r.fremote)// Move it back again, dst does not exist this timefs.Stats.ResetCounters()diff --git a/s3/s3.go b/s3/s3.goindex c0b34979e..23869c255 100644--- a/s3/s3.go+++ b/s3/s3.go@@ -242,6 +242,7 @@ type Fs struct {bucket string // the bucket we are working onbucketOKMu sync.Mutex // mutex to protect bucket OKbucketOK bool // true if we have created the bucket+ bucketDeleted bool // true if we have deleted the bucketacl string // ACL for new buckets / objectslocationConstraint string // location constraint of new bucketssse string // the type of server-side encryption@@ -670,6 +671,8 @@ func (f *Fs) Put(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.}// Check if the bucket exists+//+// NB this can return incorrect results if called immediately after bucket deletionfunc (f *Fs) dirExists() (bool, error) {req := s3.HeadBucketInput{Bucket: &f.bucket,@@ -693,12 +696,14 @@ func (f *Fs) Mkdir(dir string) error {if f.bucketOK {return nil}- exists, err := f.dirExists()- if err == nil {- f.bucketOK = exists- }- if err != nil || exists {- return err+ if !f.bucketDeleted {+ exists, err := f.dirExists()+ if err == nil {+ f.bucketOK = exists+ }+ if err != nil || exists {+ return err+ }}req := s3.CreateBucketInput{Bucket: &f.bucket,@@ -709,7 +714,7 @@ func (f *Fs) Mkdir(dir string) error {LocationConstraint: &f.locationConstraint,}}- _, err = f.c.CreateBucket(&req)+ _, err := f.c.CreateBucket(&req)if err, ok := err.(awserr.Error); ok {if err.Code() == "BucketAlreadyOwnedByYou" {err = nil@@ -717,6 +722,7 @@ func (f *Fs) Mkdir(dir string) error {}if err == nil {f.bucketOK = true+ f.bucketDeleted = false}return err}@@ -736,6 +742,7 @@ func (f *Fs) Rmdir(dir string) error {_, err := f.c.DeleteBucket(&req)if err == nil {f.bucketOK = false+ f.bucketDeleted = true}return err}