From eb0c8284f13ad2d3acdccbd695bd03b774b02577 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 19 Oct 2021 20:10:18 +0100 Subject: [PATCH] azureblob: fix incorrect size after --azureblob-no-head-object patch In 05f128868f47b1b5 azureblob: add --azureblob-no-head-object we incorrectly parsed the size of the object as the Content-Length of the returned header. This is incorrect in the presense of Range requests. This fixes the problem by parsing the Content-Range header if avaialble to read the correct length from if a Range request was issued. See: #5734 --- backend/azureblob/azureblob.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/backend/azureblob/azureblob.go b/backend/azureblob/azureblob.go index b1f657c71..84eeebedd 100644 --- a/backend/azureblob/azureblob.go +++ b/backend/azureblob/azureblob.go @@ -16,6 +16,7 @@ import ( "net/http" "net/url" "path" + "strconv" "strings" "sync" "time" @@ -1388,6 +1389,21 @@ func (o *Object) decodeMetaDataFromDownloadResponse(info *azblob.DownloadRespons o.accessTier = o.AccessTier() o.setMetadata(metadata) + // If it was a Range request, the size is wrong, so correct it + if contentRange := info.ContentRange(); contentRange != "" { + slash := strings.IndexRune(contentRange, '/') + if slash >= 0 { + i, err := strconv.ParseInt(contentRange[slash+1:], 10, 64) + if err == nil { + o.size = i + } else { + fs.Debugf(o, "Failed to find parse integer from in %q: %v", contentRange, err) + } + } else { + fs.Debugf(o, "Failed to find length in %q", contentRange) + } + } + return nil }