"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
core: Verify MD5 sums after each transfer
Nick Craig-Wood8a76568ea899
diff --git a/fs/operations.go b/fs/operations.goindex 7c838d635..0fd62d90e 100644--- a/fs/operations.go+++ b/fs/operations.go@@ -97,6 +97,18 @@ func Equal(src, dst Object) bool {return true}+// Used to remove a failed copy+func removeFailedCopy(dst Object) {+ if dst != nil {+ Debug(dst, "Removing failed copy")+ removeErr := dst.Remove()+ if removeErr != nil {+ Stats.Error()+ Log(dst, "Failed to remove failed copy: %s", removeErr)+ }+ }+}+// Copy src object to dst or f if nil//// If dst is nil then the object must not exist already. If you do@@ -126,16 +138,29 @@ func Copy(f Fs, dst, src Object) {if err != nil {Stats.Error()Log(src, "Failed to copy: %s", err)- if dst != nil {- Debug(dst, "Removing failed copy")- removeErr := dst.Remove()- if removeErr != nil {- Stats.Error()- Log(dst, "Failed to remove failed copy: %s", removeErr)- }- }+ removeFailedCopy(dst)return}++ // Verify md5sums are the same after transfer - ignoring blank md5sums+ srcMd5sum, md5sumErr := src.Md5sum()+ if md5sumErr != nil {+ Stats.Error()+ Log(src, "Failed to read md5sum: %s", md5sumErr)+ } else if srcMd5sum != "" {+ dstMd5sum, md5sumErr := dst.Md5sum()+ if md5sumErr != nil {+ Stats.Error()+ Log(dst, "Failed to read md5sum: %s", md5sumErr)+ } else if dstMd5sum != "" && srcMd5sum != dstMd5sum {+ Stats.Error()+ err = fmt.Errorf("Corrupted on transfer: md5sums differ %q vs %q", srcMd5sum, dstMd5sum)+ Log(dst, "%s", err)+ removeFailedCopy(dst)+ return+ }+ }+Debug(src, actionTaken)}