"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
Refactor Account interface
Nick Craig-Wood033d1eb7afd5
diff --git a/cmd/mount/read.go b/cmd/mount/read.goindex 2680d9fd4..a468fde3a 100644--- a/cmd/mount/read.go+++ b/cmd/mount/read.go@@ -29,7 +29,7 @@ func newReadFileHandle(o fs.Object) (*ReadFileHandle, error) {}fh := &ReadFileHandle{o: o,- r: fs.NewAccountWithBuffer(r, o), // account the transfer+ r: fs.NewAccount(r, o).WithBuffer(), // account the transfer}fs.Stats.Transferring(fh.o.Remote())return fh, nildiff --git a/cmd/mount/write.go b/cmd/mount/write.goindex 589b6231c..6ab7263a6 100644--- a/cmd/mount/write.go+++ b/cmd/mount/write.go@@ -38,7 +38,7 @@ func newWriteFileHandle(d *Dir, f *File, src fs.ObjectInfo) (*WriteFileHandle, efile: f,}fh.pipeReader, fh.pipeWriter = io.Pipe()- r := fs.NewAccountSizeNameWithBuffer(fh.pipeReader, 0, src.Remote()) // account the transfer+ r := fs.NewAccountSizeName(fh.pipeReader, 0, src.Remote()).WithBuffer() // account the transfergo func() {o, err := d.f.Put(r, src)fh.o = odiff --git a/fs/accounting.go b/fs/accounting.goindex e9d6163e9..4312b2ac7 100644--- a/fs/accounting.go+++ b/fs/accounting.go@@ -346,44 +346,27 @@ func NewAccount(in io.ReadCloser, obj Object) *Account {return NewAccountSizeName(in, obj.Size(), obj.Remote())}-// bufferReadCloser returns a buffered version of in if necessary-func bufferReadCloser(in io.ReadCloser, size int64, name string) io.ReadCloser {+// WithBuffer - If the file is above a certain size it adds an Async reader+func (acc *Account) WithBuffer() *Account {+ acc.withBuf = truevar buffers int- if size >= int64(Config.BufferSize) {+ if acc.size >= int64(Config.BufferSize) {buffers = int(int64(Config.BufferSize) / asyncBufferSize)} else {- buffers = int(size / asyncBufferSize)+ buffers = int(acc.size / asyncBufferSize)}// On big files add a bufferif buffers > 0 {- newIn, err := newAsyncReader(in, buffers)+ in, err := newAsyncReader(acc.in, buffers)if err != nil {- Errorf(name, "Failed to make buffer: %v", err)+ Errorf(acc.name, "Failed to make buffer: %v", err)} else {- in = newIn+ acc.in = in}}- return in-}--// NewAccountSizeNameWithBuffer makes a Account reader for an io.ReadCloser of-// the given size and name-//-// If the file is above a certain size it adds an Async reader-func NewAccountSizeNameWithBuffer(in io.ReadCloser, size int64, name string) *Account {- acc := NewAccountSizeName(in, size, name)- acc.in = bufferReadCloser(in, size, name)- acc.withBuf = truereturn acc}-// NewAccountWithBuffer makes a Account reader for an object-//-// If the file is above a certain size it adds an Async reader-func NewAccountWithBuffer(in io.ReadCloser, obj Object) *Account {- return NewAccountSizeNameWithBuffer(in, obj.Size(), obj.Remote())-}-// GetReader returns the underlying io.ReadCloserfunc (acc *Account) GetReader() io.ReadCloser {acc.mu.Lock()@@ -402,12 +385,9 @@ func (acc *Account) StopBuffering() {func (acc *Account) UpdateReader(in io.ReadCloser) {acc.mu.Lock()acc.StopBuffering()+ acc.in = inacc.origIn = in- if acc.withBuf {- acc.in = bufferReadCloser(in, acc.size, acc.name)- } else {- acc.in = in- }+ acc.WithBuffer()acc.mu.Unlock()}diff --git a/fs/operations.go b/fs/operations.goindex c3d5fdcfd..f91398039 100644--- a/fs/operations.go+++ b/fs/operations.go@@ -273,7 +273,7 @@ func Copy(f Fs, dst Object, remote string, src Object) (err error) {if err != nil {err = errors.Wrap(err, "failed to open source object")} else {- in := NewAccountWithBuffer(in0, src) // account and buffer the transfer+ in := NewAccount(in0, src).WithBuffer() // account and buffer the transferwrappedSrc := &overrideRemoteObject{Object: src, remote: remote}if doUpdate {@@ -843,14 +843,14 @@ func CheckIdentical(dst, src Object) (differ bool, err error) {if err != nil {return true, errors.Wrapf(err, "failed to open %q", dst)}- in1 = NewAccountWithBuffer(in1, dst) // account and buffer the transfer+ in1 = NewAccount(in1, dst).WithBuffer() // account and buffer the transferdefer CheckClose(in1, &err)in2, err := src.Open()if err != nil {return true, errors.Wrapf(err, "failed to open %q", src)}- in2 = NewAccountWithBuffer(in2, src) // account and buffer the transfer+ in2 = NewAccount(in2, src).WithBuffer() // account and buffer the transferdefer CheckClose(in2, &err)return CheckEqualReaders(in1, in2)@@ -1388,7 +1388,7 @@ func Cat(f Fs, w io.Writer, offset, count int64) error {size = count}}- in = NewAccountSizeNameWithBuffer(in, size, o.Remote()) // account and buffer the transfer+ in = NewAccountSizeName(in, size, o.Remote()).WithBuffer() // account and buffer the transferdefer func() {err = in.Close()if err != nil {