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

vfs: fix --vfs-cache-mode minimal,writes ignoring cached files

Nick Craig-Wood077b45322d89
diff --git a/vfs/cache.go b/vfs/cache.go
index 87b0b3104..acb51138a 100644
--- a/vfs/cache.go
+++ b/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 {
diff --git a/vfs/file.go b/vfs/file.go
index 0622f4cf9..a28480235 100644
--- a/vfs/file.go
+++ b/vfs/file.go
@@ -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 {