mirror of
https://github.com/rclone/rclone.git
synced 2024-12-22 15:11:56 +01:00
vfs: cache: factor common code from InUse and DirtyItem into ItemOrNil
This commit is contained in:
parent
fb4600f6f9
commit
f07abea072
@ -294,14 +294,22 @@ func (c *Cache) put(name string, item *Item) (oldItem *Item) {
|
||||
return oldItem
|
||||
}
|
||||
|
||||
// ItemOrNil returns the Item if it exists in the cache otherwise it
|
||||
// returns nil.
|
||||
//
|
||||
// name should be a remote path not an osPath
|
||||
func (c *Cache) ItemOrNil(name string) (item *Item) {
|
||||
name = clean(name)
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
return c.item[name]
|
||||
}
|
||||
|
||||
// InUse returns whether the name is in use in the cache
|
||||
//
|
||||
// name should be a remote path not an osPath
|
||||
func (c *Cache) InUse(name string) bool {
|
||||
name = clean(name)
|
||||
c.mu.Lock()
|
||||
item := c.item[name]
|
||||
c.mu.Unlock()
|
||||
item := c.ItemOrNil(name)
|
||||
if item == nil {
|
||||
return false
|
||||
}
|
||||
@ -313,10 +321,7 @@ func (c *Cache) InUse(name string) bool {
|
||||
//
|
||||
// name should be a remote path not an osPath
|
||||
func (c *Cache) DirtyItem(name string) (item *Item) {
|
||||
name = clean(name)
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
item = c.item[name]
|
||||
item = c.ItemOrNil(name)
|
||||
if item != nil && !item.IsDirty() {
|
||||
item = nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user