Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

azureblob: fix MD5 being dropped on range reads causing vfs cache re-downloads

Nick Craig-Wood70c815d1b7fe
diff --git a/backend/azureblob/azureblob.go b/backend/azureblob/azureblob.go
index 11b68521c..a2e52eecf 100644
--- a/backend/azureblob/azureblob.go
+++ b/backend/azureblob/azureblob.go
@@ -2185,7 +2185,16 @@ func (o *Object) decodeMetaDataFromDownloadResponse(info *blob.DownloadStreamRes
}
// NOTE - Client library always returns MD5 as base64 decoded string, Object needs to maintain
// this as base64 encoded string.
- o.md5 = base64.StdEncoding.EncodeToString(info.ContentMD5)
+ //
+ // On a range request the service returns the whole-blob MD5 in the
+ // x-ms-blob-content-md5 header (BlobContentMD5) and leaves Content-MD5
+ // (ContentMD5) empty, so prefer BlobContentMD5. Never overwrite a known
+ // hash with an empty one, or a ranged read would drop the object's MD5.
+ if md5 := info.BlobContentMD5; len(md5) > 0 {
+ o.md5 = base64.StdEncoding.EncodeToString(md5)
+ } else if len(info.ContentMD5) > 0 {
+ o.md5 = base64.StdEncoding.EncodeToString(info.ContentMD5)
+ }
if info.ContentType == nil {
o.mimeType = ""
} else {