mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 09:04:52 +01:00
vfs: fix --vfs-cache-mode minimal,writes ignoring cached files
Before this change, with --vfs-cache-mode minimal,writes if files were opened they would always be read from the remote, regardless of whether they were in the cache or not. This change checks to see if the file is in the cache when opening a file with --vfs-cache-mode >= minimal and if so then it uses it from the cache. This makes --vfs-cache-mode writes in particular much more efficient. No longer is a file uploaded (with write mode) then immediately downloaded (with read only mode). Fixes #3330
This commit is contained in:
parent
67fae720d7
commit
077b45322d
13
vfs/cache.go
13
vfs/cache.go
@ -263,6 +263,19 @@ func (c *cache) cacheDir(name string) {
|
||||
}
|
||||
}
|
||||
|
||||
// exists checks to see if the file exists in the cache or not
|
||||
func (c *cache) exists(name string) bool {
|
||||
osPath := c.toOSPath(name)
|
||||
fi, err := os.Stat(osPath)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if fi.IsDir() {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// _close marks name as closed - must be called with the lock held
|
||||
func (c *cache) _close(isFile bool, name string) {
|
||||
for {
|
||||
|
@ -546,11 +546,9 @@ func (f *File) Open(flags int) (fd Handle, err error) {
|
||||
write = true
|
||||
}
|
||||
|
||||
// FIXME discover if file is in cache or not?
|
||||
|
||||
// Open the correct sort of handle
|
||||
CacheMode := f.d.vfs.Opt.CacheMode
|
||||
if CacheMode >= CacheModeMinimal && f.d.vfs.cache.opens(f.Path()) > 0 {
|
||||
if CacheMode >= CacheModeMinimal && (f.d.vfs.cache.opens(f.Path()) > 0 || f.d.vfs.cache.exists(f.Path())) {
|
||||
fd, err = f.openRW(flags)
|
||||
} else if read && write {
|
||||
if CacheMode >= CacheModeMinimal {
|
||||
|
Loading…
Reference in New Issue
Block a user