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

lib/bucket: shorten locking window where possible

Nick Craig-Woode339c9ff8f06
diff --git a/lib/bucket/bucket.go b/lib/bucket/bucket.go
index 45065c474..2ebc14d33 100644
--- a/lib/bucket/bucket.go
+++ b/lib/bucket/bucket.go
@@ -78,16 +78,16 @@ type (
//
// If f returns an error we assume the bucket was not created
func (c *Cache) Create(bucket string, create CreateFn, exists ExistsFn) (err error) {
- c.createMu.Lock()
- defer c.createMu.Unlock()
- c.mu.Lock()
- defer c.mu.Unlock()
-
// if we are at the root, then it is OK
if bucket == "" {
return nil
}
+ c.createMu.Lock()
+ defer c.createMu.Unlock()
+ c.mu.Lock()
+ defer c.mu.Unlock()
+
// if have exists fuction and bucket has been deleted, check
// it still exists
if created, ok := c.status[bucket]; ok && !created && exists != nil {
@@ -124,16 +124,16 @@ func (c *Cache) Create(bucket string, create CreateFn, exists ExistsFn) (err err
//
// If the bucket has already been deleted it returns ErrAlreadyDeleted
func (c *Cache) Remove(bucket string, f func() error) error {
- c.removeMu.Lock()
- defer c.removeMu.Unlock()
- c.mu.Lock()
- defer c.mu.Unlock()
-
// if we are at the root, then it is OK
if bucket == "" {
return nil
}
+ c.removeMu.Lock()
+ defer c.removeMu.Unlock()
+ c.mu.Lock()
+ defer c.mu.Unlock()
+
// If bucket already deleted then it is OK
if created, ok := c.status[bucket]; ok && !created {
return ErrAlreadyDeleted