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 IO Error opening a file with O_CREATE|O_RDONLY in --vfs-cache-mode not full

Nick Craig-Wood46b080c0922f
diff --git a/vfs/file.go b/vfs/file.go
index 4e59aee74..aa2493a5f 100644
--- a/vfs/file.go
+++ b/vfs/file.go
@@ -698,6 +698,11 @@ func (f *File) Open(flags int) (fd Handle, err error) {
write = true
}
+ // If create is set then set write to force openRW
+ if flags&os.O_CREATE != 0 {
+ write = true
+ }
+
// Open the correct sort of handle
f.mu.RLock()
d := f.d
diff --git a/vfs/read_write_test.go b/vfs/read_write_test.go
index ee8051c86..d9dac353f 100644
--- a/vfs/read_write_test.go
+++ b/vfs/read_write_test.go
@@ -642,15 +642,19 @@ func testRWFileHandleOpenTest(t *testing.T, vfs *VFS, test *openTest) {
}
func TestRWFileHandleOpenTests(t *testing.T) {
- opt := vfscommon.DefaultOpt
- opt.CacheMode = vfscommon.CacheModeFull
- opt.WriteBack = writeBackDelay
- _, vfs, cleanup := newTestVFSOpt(t, &opt)
- defer cleanup()
-
- for _, test := range openTests {
- t.Run(test.what, func(t *testing.T) {
- testRWFileHandleOpenTest(t, vfs, &test)
+ for _, cacheMode := range []vfscommon.CacheMode{vfscommon.CacheModeWrites, vfscommon.CacheModeFull} {
+ t.Run(cacheMode.String(), func(t *testing.T) {
+ opt := vfscommon.DefaultOpt
+ opt.CacheMode = cacheMode
+ opt.WriteBack = writeBackDelay
+ _, vfs, cleanup := newTestVFSOpt(t, &opt)
+ defer cleanup()
+
+ for _, test := range openTests {
+ t.Run(test.what, func(t *testing.T) {
+ testRWFileHandleOpenTest(t, vfs, &test)
+ })
+ }
})
}
}