diff --git a/fs/sync_test.go b/fs/sync_test.go index 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 moving require.NoError(t, fs.Purge(r.fremote)) + fstest.CheckItems(t, r.fremote) // Move it back again, dst does not exist this time fs.Stats.ResetCounters() diff --git a/s3/s3.go b/s3/s3.go index 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 on bucketOKMu sync.Mutex // mutex to protect bucket OK bucketOK bool // true if we have created the bucket + bucketDeleted bool // true if we have deleted the bucket acl string // ACL for new buckets / objects locationConstraint string // location constraint of new buckets sse 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 deletion func (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 }