"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
vfs: rename Fsync to Sync and implement Sync on Node and Handle
Nick Craig-Woodb4083b4371ee
diff --git a/cmd/mount/dir.go b/cmd/mount/dir.goindex 8cef250a5..d0485f878 100644--- a/cmd/mount/dir.go+++ b/cmd/mount/dir.go@@ -174,7 +174,7 @@ var _ fusefs.NodeFsyncer = (*Dir)(nil)// Fsync the directoryfunc (d *Dir) Fsync(ctx context.Context, req *fuse.FsyncRequest) (err error) {defer fs.Trace(d, "")("err=%v", &err)- err = d.Dir.Fsync()+ err = d.Dir.Sync()if err != nil {return translateError(err)}diff --git a/vfs/dir.go b/vfs/dir.goindex 962aa460d..1637c0bd2 100644--- a/vfs/dir.go+++ b/vfs/dir.go@@ -498,10 +498,10 @@ func (d *Dir) Rename(oldName, newName string, destDir *Dir) error {return nil}-// Fsync the directory+// Sync the directory//// Note that we don't do anything except return OK-func (d *Dir) Fsync() error {+func (d *Dir) Sync() error {return nil}diff --git a/vfs/dir_test.go b/vfs/dir_test.goindex 5c9fc0bc6..c8f20614a 100644--- a/vfs/dir_test.go+++ b/vfs/dir_test.go@@ -64,8 +64,8 @@ func TestDirMethods(t *testing.T) {// Sizeassert.Equal(t, int64(0), dir.Size())- // Fsync- assert.NoError(t, dir.Fsync())+ // Sync+ assert.NoError(t, dir.Sync())// DirEntryassert.Equal(t, dir.entry, dir.DirEntry())diff --git a/vfs/file.go b/vfs/file.goindex f2bce87e0..5fa495c2b 100644--- a/vfs/file.go+++ b/vfs/file.go@@ -293,10 +293,10 @@ func (f *File) OpenRW(flags int) (fh *RWFileHandle, err error) {return fh, nil}-// Fsync the file+// Sync the file//// Note that we don't do anything except return OK-func (f *File) Fsync() error {+func (f *File) Sync() error {return nil}diff --git a/vfs/file_test.go b/vfs/file_test.goindex 3c6e206f3..1c9eb9c67 100644--- a/vfs/file_test.go+++ b/vfs/file_test.go@@ -62,8 +62,8 @@ func TestFileMethods(t *testing.T) {// Sizeassert.Equal(t, int64(14), file.Size())- // Fsync- assert.NoError(t, file.Fsync())+ // Sync+ assert.NoError(t, file.Sync())// DirEntryassert.Equal(t, file.o, file.DirEntry())diff --git a/vfs/read_write.go b/vfs/read_write.goindex 68c2ae569..d66bb3d77 100644--- a/vfs/read_write.go+++ b/vfs/read_write.go@@ -408,3 +408,18 @@ func (fh *RWFileHandle) Truncate(size int64) (err error) {fh.file.setSize(size)return fh.File.Truncate(size)}++// Sync commits the current contents of the file to stable storage. Typically,+// this means flushing the file system's in-memory copy of recently written+// data to disk.+func (fh *RWFileHandle) Sync() error {+ fh.mu.Lock()+ defer fh.mu.Unlock()+ if fh.closed {+ return ECLOSED+ }+ if !fh.opened {+ return nil+ }+ return fh.File.Sync()+}diff --git a/vfs/read_write_test.go b/vfs/read_write_test.goindex 49f0b46b2..6f482cf5a 100644--- a/vfs/read_write_test.go+++ b/vfs/read_write_test.go@@ -78,6 +78,10 @@ func TestRWFileHandleMethodsRead(t *testing.T) {_, err := fh.Read(buf)assert.Equal(t, io.EOF, err)+ // Sync+ err = fh.Sync()+ assert.NoError(t, err)+// Statvar fi os.FileInfofi, err = fh.Stat()diff --git a/vfs/vfs.go b/vfs/vfs.goindex 14e646a25..4d20e89a9 100644--- a/vfs/vfs.go+++ b/vfs/vfs.go@@ -54,7 +54,7 @@ type Node interface {IsFile() boolInode() uint64SetModTime(modTime time.Time) error- Fsync() error+ Sync() errorRemove() errorRemoveAll() errorDirEntry() fs.DirEntrydiff --git a/vfs/write.go b/vfs/write.goindex 3c107f486..5c68ba540 100644--- a/vfs/write.go+++ b/vfs/write.go@@ -264,3 +264,10 @@ func (fh *WriteFileHandle) ReadAt(p []byte, off int64) (n int, err error) {fs.Errorf(fh.remote, "ReadAt: Can't read and write to file without cache")return 0, EPERM}++// Sync commits the current contents of the file to stable storage. Typically,+// this means flushing the file system's in-memory copy of recently written+// data to disk.+func (fh *WriteFileHandle) Sync() error {+ return nil+}diff --git a/vfs/write_test.go b/vfs/write_test.goindex daadeeea8..45d66f6b4 100644--- a/vfs/write_test.go+++ b/vfs/write_test.go@@ -65,6 +65,10 @@ func TestWriteFileHandleMethods(t *testing.T) {_, err = fh.ReadAt(buf, 0)assert.Equal(t, EPERM, err)+ // Sync+ err = fh.Sync()+ assert.NoError(t, err)+// Closeassert.NoError(t, fh.Close())