mirror of
https://github.com/rclone/rclone.git
synced 2024-12-31 19:40:25 +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
|
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
|
// InUse returns whether the name is in use in the cache
|
||||||
//
|
//
|
||||||
// name should be a remote path not an osPath
|
// name should be a remote path not an osPath
|
||||||
func (c *Cache) InUse(name string) bool {
|
func (c *Cache) InUse(name string) bool {
|
||||||
name = clean(name)
|
item := c.ItemOrNil(name)
|
||||||
c.mu.Lock()
|
|
||||||
item := c.item[name]
|
|
||||||
c.mu.Unlock()
|
|
||||||
if item == nil {
|
if item == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -313,10 +321,7 @@ func (c *Cache) InUse(name string) bool {
|
|||||||
//
|
//
|
||||||
// name should be a remote path not an osPath
|
// name should be a remote path not an osPath
|
||||||
func (c *Cache) DirtyItem(name string) (item *Item) {
|
func (c *Cache) DirtyItem(name string) (item *Item) {
|
||||||
name = clean(name)
|
item = c.ItemOrNil(name)
|
||||||
c.mu.Lock()
|
|
||||||
defer c.mu.Unlock()
|
|
||||||
item = c.item[name]
|
|
||||||
if item != nil && !item.IsDirty() {
|
if item != nil && !item.IsDirty() {
|
||||||
item = nil
|
item = nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user