"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: stop reading File members from outside file.go
Nick Craig-Wood238f26cc9036
diff --git a/vfs/file.go b/vfs/file.goindex 7159b8965..c330f33db 100644--- a/vfs/file.go+++ b/vfs/file.go@@ -607,6 +607,13 @@ func (f *File) VFS() *VFS {return f.d.vfs}+// Fs returns the underlying Fs for the file+func (f *File) Fs() fs.Fs {+ f.mu.RLock()+ defer f.mu.RUnlock()+ return f.d.f+}+// Open a file according to the flags provided//// O_RDONLY open the file read-only.diff --git a/vfs/read.go b/vfs/read.goindex 526467616..6324593dc 100644--- a/vfs/read.go+++ b/vfs/read.go@@ -47,7 +47,7 @@ func newReadFileHandle(f *File) (*ReadFileHandle, error) {var mhash *hash.MultiHashervar err erroro := f.getObject()- if !f.d.vfs.Opt.NoChecksum {+ if !f.VFS().Opt.NoChecksum {hashes := hash.NewHashSet(o.Fs().Hashes().GetOne()) // just pick one hashmhash, err = hash.NewMultiHasherTypes(hashes)if err != nil {@@ -57,7 +57,7 @@ func newReadFileHandle(f *File) (*ReadFileHandle, error) {fh := &ReadFileHandle{remote: o.Remote(),- noSeek: f.d.vfs.Opt.NoSeek,+ noSeek: f.VFS().Opt.NoSeek,file: f,hash: mhash,size: nonNegative(o.Size()),@@ -74,7 +74,7 @@ func (fh *ReadFileHandle) openPending() (err error) {return nil}o := fh.file.getObject()- r, err := chunkedreader.New(context.TODO(), o, int64(fh.file.d.vfs.Opt.ChunkSize), int64(fh.file.d.vfs.Opt.ChunkSizeLimit)).Open()+ r, err := chunkedreader.New(context.TODO(), o, int64(fh.file.VFS().Opt.ChunkSize), int64(fh.file.VFS().Opt.ChunkSizeLimit)).Open()if err != nil {return err}@@ -147,7 +147,7 @@ func (fh *ReadFileHandle) seek(offset int64, reopen bool) (err error) {}// re-open with a seeko := fh.file.getObject()- r = chunkedreader.New(context.TODO(), o, int64(fh.file.d.vfs.Opt.ChunkSize), int64(fh.file.d.vfs.Opt.ChunkSizeLimit))+ r = chunkedreader.New(context.TODO(), o, int64(fh.file.VFS().Opt.ChunkSize), int64(fh.file.VFS().Opt.ChunkSizeLimit))_, err := r.Seek(offset, 0)if err != nil {fs.Debugf(fh.remote, "ReadFileHandle.Read seek failed: %v", err)@@ -235,7 +235,7 @@ func (fh *ReadFileHandle) readAt(p []byte, off int64) (n int, err error) {// The default time here was made by finding the// smallest when mounting a local backend that didn't// cause seeks.- maxWait := fh.file.d.vfs.Opt.ReadWait+ maxWait := fh.file.VFS().Opt.ReadWaittimeout := time.NewTimer(maxWait)done := make(chan struct{})abort := int32(0)diff --git a/vfs/write.go b/vfs/write.goindex e45752360..b7401bbe9 100644--- a/vfs/write.go+++ b/vfs/write.go@@ -69,7 +69,7 @@ func (fh *WriteFileHandle) openPending() (err error) {pipeReader, fh.pipeWriter = io.Pipe()go func() {// NB Rcat deals with Stats.Transferring etc- o, err := operations.Rcat(context.TODO(), fh.file.d.f, fh.remote, pipeReader, time.Now())+ o, err := operations.Rcat(context.TODO(), fh.file.Fs(), fh.remote, pipeReader, time.Now())if err != nil {fs.Errorf(fh.remote, "WriteFileHandle.New Rcat failed: %v", err)}@@ -80,7 +80,7 @@ func (fh *WriteFileHandle) openPending() (err error) {}()fh.file.setSize(0)fh.truncated = true- fh.file.d.addObject(fh.file) // make sure the directory has this object in it now+ fh.file.Dir().addObject(fh.file) // make sure the directory has this object in it nowfh.opened = truereturn nil}@@ -132,7 +132,7 @@ func (fh *WriteFileHandle) writeAt(p []byte, off int64) (n int, err error) {}if fh.offset != off {// Set a background timer so we don't wait forever- maxWait := fh.file.d.vfs.Opt.WriteWait+ maxWait := fh.file.VFS().Opt.WriteWaittimeout := time.NewTimer(maxWait)done := make(chan struct{})abort := int32(0)