mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 08:58:26 +08:00
lib/bucket: shorten locking window where possible
This commit is contained in:
parent
3247e69cf5
commit
e339c9ff8f
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user