"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
Check the MD5SUM of an object if the mtime is different before uploading
Nick Craig-Wooddbb039af9f5b
diff --git a/swiftsync.go b/swiftsync.goindex fb4d04d15..2acc31cbe 100644--- a/swiftsync.go+++ b/swiftsync.go@@ -65,12 +65,20 @@ func (fs *FsObject) md5sum() (string, error) {return fmt.Sprintf("%x", hash.Sum(nil)), nil}-// Checks to see if an object has changed or not by looking at its size and mtime+// Checks to see if an object has changed or not by looking at its size, mtime and MD5SUM//-// This is the heuristic rsync uses when not using --checksum+// If the remote object size is different then it is considered to be+// changed.//-// If the remote object doesn't have the mtime metadata set then the-// checksum is checked+// If the size is the same and the mtime is the same then it is+// considered to be unchanged. This is the heuristic rsync uses when+// not using --checksum.+//+// If the size is the same and and mtime is different or unreadable+// and the MD5SUM is the same then the file is considered to be+// unchanged.+//+// Otherwise the file is considered to be changed.//// FIXME should update the checksum of the remote object with the mtimefunc (fs *FsObject) changed(c *swift.Connection, container string) bool {@@ -83,29 +91,35 @@ func (fs *FsObject) changed(c *swift.Connection, container string) bool {fs.Debugf("Sizes differ")return true}++ // Size the same so check the mtimem := h.ObjectMetadata()t, err := m.GetModTime()if err != nil {fs.Debugf("Failed to read mtime: %s", err)- localMd5, err := fs.md5sum()- // fs.Debugf("Local MD5 %s", localMd5)- // fs.Debugf("Remote MD5 %s", obj.Hash)- if err != nil {- fs.Debugf("Failed to calculate md5: %s", err)- return true- }- if localMd5 != strings.ToLower(obj.Hash) {- fs.Debugf("Md5sums differ")- return true- }- fs.Debugf("Md5sums identical - skipping")- // FIXME update the mtime of the remote object here+ } else if !t.Equal(fs.info.ModTime()) {+ fs.Debugf("Modification times differ")+ } else {+ fs.Debugf("Size and modification time the same - skipping")return false+ }++ // mtime is unreadable or different but size is the same so+ // check the MD5SUM+ localMd5, err := fs.md5sum()+ if err != nil {+ fs.Debugf("Failed to calculate md5: %s", err)+ return true}- if !t.Equal(fs.info.ModTime()) {- fs.Debugf("Modification times differ")+ // fs.Debugf("Local MD5 %s", localMd5)+ // fs.Debugf("Remote MD5 %s", obj.Hash)+ if localMd5 != strings.ToLower(obj.Hash) {+ fs.Debugf("Md5sums differ")return true}++ // FIXME update the mtime of the remote object here+ fs.Debugf("Size and MD5SUM identical - skipping")return false}