"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 a code path which allows dirty data to be removed causing data loss
Nick Craig-Wood2a40f0007708
diff --git a/vfs/vfscache/item.go b/vfs/vfscache/item.goindex b7f6f0700..7c42563c8 100644--- a/vfs/vfscache/item.go+++ b/vfs/vfscache/item.go@@ -774,6 +774,9 @@ func (item *Item) reload(ctx context.Context) error {// check the fingerprint of an object and update the item or delete// the cached file accordingly//+// If we have local modifications then they take precedence+// over a change in the remote+//// It ensures the file is the correct size for the object//// call with lock held@@ -781,8 +784,12 @@ func (item *Item) _checkObject(o fs.Object) error {if o == nil {if item.info.Fingerprint != "" {// no remote object && local object- // remove local object- item._remove("stale (remote deleted)")+ // remove local object unless dirty+ if !item.info.Dirty {+ item._remove("stale (remote deleted)")+ } else {+ fs.Debugf(item.name, "vfs cache: remote object has gone but local object modified - keeping it")+ }} else {// no remote object && no local object// OK@@ -793,8 +800,12 @@ func (item *Item) _checkObject(o fs.Object) error {if item.info.Fingerprint != "" {// remote object && local objectif remoteFingerprint != item.info.Fingerprint {- fs.Debugf(item.name, "vfs cache: removing cached entry as stale (remote fingerprint %q != cached fingerprint %q)", remoteFingerprint, item.info.Fingerprint)- item._remove("stale (remote is different)")+ if !item.info.Dirty {+ fs.Debugf(item.name, "vfs cache: removing cached entry as stale (remote fingerprint %q != cached fingerprint %q)", remoteFingerprint, item.info.Fingerprint)+ item._remove("stale (remote is different)")+ } else {+ fs.Debugf(item.name, "vfs cache: remote object has changed but local object modified - keeping it (remote fingerprint %q != cached fingerprint %q)", remoteFingerprint, item.info.Fingerprint)+ }}} else {// remote object && no local object