azureblob: fix incorrect size after --azureblob-no-head-object patch

In

05f128868f 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
This commit is contained in:
Nick Craig-Wood 2021-10-19 20:10:18 +01:00
parent f5c7c597ba
commit eb0c8284f1
1 changed files with 16 additions and 0 deletions

View File

@ -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
}