"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: decouple writeback from Item so it can be tested
Nick Craig-Wood43018973acc2
diff --git a/vfs/vfscache/item.go b/vfs/vfscache/item.goindex db1a4e596..14409ffa3 100644--- a/vfs/vfscache/item.go+++ b/vfs/vfscache/item.go@@ -608,7 +608,9 @@ func (item *Item) Close(storeFn StoreFn) (err error) {} else {// asynchronous writebackitem.mu.Unlock()- item.c.writeback.add(item, item.name, item.modified, storeFn)+ item.c.writeback.add(item, item.name, item.modified, func(ctx context.Context) error {+ return item.store(ctx, storeFn)+ })item.mu.Lock()}}diff --git a/vfs/vfscache/writeback.go b/vfs/vfscache/writeback.goindex bab5029d2..c4bcde4ba 100644--- a/vfs/vfscache/writeback.go+++ b/vfs/vfscache/writeback.go@@ -17,6 +17,9 @@ const (maxUploadDelay = 5 * time.Minute // max delay betwen upload attempts)+// putFn is the interface that item provides to store the data+type putFn func(context.Context) error+// writeBack keeps track of the items which need to be written back to the disk at some pointtype writeBack struct {mu sync.Mutex@@ -61,7 +64,7 @@ type writeBackItem struct {onHeap bool // true if this item is on the items heapcancel context.CancelFunc // To cancel the upload withdone chan struct{} // closed when the cancellation completes- storeFn StoreFn // To write the object back with+ putFn putFn // To write the object datatries int // number of times we have tried to uploaddelay time.Duration // delay between upload attempts}@@ -204,7 +207,7 @@ func (wb *writeBack) _resetTimer() {// is already there.//// if modified is false then it it doesn't a pending upload-func (wb *writeBack) add(item *Item, name string, modified bool, storeFn StoreFn) {+func (wb *writeBack) add(item *Item, name string, modified bool, putFn putFn) {wb.mu.Lock()defer wb.mu.Unlock()@@ -219,7 +222,7 @@ func (wb *writeBack) add(item *Item, name string, modified bool, storeFn StoreFn// Kick the timer onwb.items._update(wbItem, wb._newExpiry())}- wbItem.storeFn = storeFn+ wbItem.putFn = putFnwb._resetTimer()}@@ -264,11 +267,11 @@ func (wb *writeBack) _kickUploader() {func (wb *writeBack) upload(ctx context.Context, wbItem *writeBackItem) {wb.mu.Lock()defer wb.mu.Unlock()- item := wbItem.item+ putFn := wbItem.putFnwbItem.tries++wb.mu.Unlock()- err := item.store(ctx, wbItem.storeFn)+ err := putFn(ctx)wb.mu.Lock()wbItem.cancel() // cancel context to release resources since store done