"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
crypt: fix hash mismatches with no_data_encryption on backends which check upload hashes
Nick Craig-Wood5a0b7d6746cc
diff --git a/backend/crypt/crypt.go b/backend/crypt/crypt.goindex 1c02aaa7d..13f5f0246 100644--- a/backend/crypt/crypt.go+++ b/backend/crypt/crypt.go@@ -1179,6 +1179,11 @@ func (o *ObjectInfo) Size() int64 {// Hash returns the selected checksum of the file// If no checksum is available it returns ""func (o *ObjectInfo) Hash(ctx context.Context, hash hash.Type) (string, error) {+ // If the data is unchanged then the hash of the source is the+ // hash of the object which will be uploaded+ if o.f.opt.NoDataEncryption {+ return o.ObjectInfo.Hash(ctx, hash)+ }var srcObj fs.Objectvar ok bool// Get the underlying object if there is onediff --git a/backend/crypt/crypt_internal_test.go b/backend/crypt/crypt_internal_test.goindex a6eaecbc5..8cf49a396 100644--- a/backend/crypt/crypt_internal_test.go+++ b/backend/crypt/crypt_internal_test.go@@ -84,6 +84,10 @@ func testObjectInfo(t *testing.T, f *Fs, wrap bool) {// Test ObjectInfo.HashwantHash := md5.Sum(outBuf.Bytes())+ if f.opt.NoDataEncryption {+ // If the data isn't encrypted, the hash should be that of the plaintext+ wantHash = md5.Sum([]byte(contents))+ }gotHash, err := src.Hash(ctx, hash.MD5)require.NoError(t, err)assert.Equal(t, fmt.Sprintf("%x", wantHash), gotHash)