"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: fix download loop when file size shrunk
Nick Craig-Woodf3f743c3f983
diff --git a/vfs/vfscache/downloaders/downloaders.go b/vfs/vfscache/downloaders/downloaders.goindex b0dd6b508..2546afdd9 100644--- a/vfs/vfscache/downloaders/downloaders.go+++ b/vfs/vfscache/downloaders/downloaders.go@@ -359,6 +359,10 @@ func (dls *Downloaders) _ensureDownloader(r ranges.Range) (err error) {if !startNew {return nil}+ // Size can be 0 here if file shrinks - no need to download+ if r.Size == 0 {+ return nil+ }// Downloader not found so start a new one_, err = dls._newDownloader(r)if err != nil {@@ -389,7 +393,10 @@ func (dls *Downloaders) _dispatchWaiters() {newWaiters := dls.waiters[:0]for _, waiter := range dls.waiters {- if dls.item.HasRange(waiter.r) {+ // Clip the size against the actual size in case it has shrunk+ r := waiter.r+ r.Clip(dls.src.Size())+ if dls.item.HasRange(r) {waiter.errChan <- nil} else {newWaiters = append(newWaiters, waiter)diff --git a/vfs/vfscache/item.go b/vfs/vfscache/item.goindex 34962a503..6cc68d1e5 100644--- a/vfs/vfscache/item.go+++ b/vfs/vfscache/item.go@@ -1279,6 +1279,15 @@ func (item *Item) readAt(b []byte, off int64) (n int, err error) {return 0, err}+ // Check to see if object has shrunk - if so don't read too much.+ if item.o != nil && !item.info.Dirty && item.o.Size() != item.info.Size {+ fs.Debugf(item.o, "Size has changed from %d to %d", item.info.Size, item.o.Size())+ err = item._truncate(item.o.Size())+ if err != nil {+ return 0, err+ }+ }+item.info.ATime = time.Now()// Do the reading with Item.mu unlocked and cache protected by preAccessn, err = item.fd.ReadAt(b, off)