mirror of
https://github.com/rclone/rclone.git
synced 2025-01-20 03:32:44 +08:00
b2: force the case of the SHA1 to lowercase - fixes #4162
Apparently some tools (eg duplicati) upload the SHA1 in uppercase to b2 to be stored in the `large_file_sha1` metadata. This patch forces it to lower case.
This commit is contained in:
parent
54edf38d0e
commit
74d9dabdff
|
@ -1375,6 +1375,21 @@ func (o *Object) Size() int64 {
|
||||||
return o.size
|
return o.size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean the SHA1
|
||||||
|
//
|
||||||
|
// Make sure it is lower case
|
||||||
|
//
|
||||||
|
// Remove unverified prefix - see https://www.backblaze.com/b2/docs/uploading.html
|
||||||
|
// Some tools (eg Cyberduck) use this
|
||||||
|
func cleanSHA1(sha1 string) (out string) {
|
||||||
|
out = strings.ToLower(sha1)
|
||||||
|
const unverified = "unverified:"
|
||||||
|
if strings.HasPrefix(out, unverified) {
|
||||||
|
out = out[len(unverified):]
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
// decodeMetaDataRaw sets the metadata from the data passed in
|
// decodeMetaDataRaw sets the metadata from the data passed in
|
||||||
//
|
//
|
||||||
// Sets
|
// Sets
|
||||||
|
@ -1390,12 +1405,7 @@ func (o *Object) decodeMetaDataRaw(ID, SHA1 string, Size int64, UploadTimestamp
|
||||||
if o.sha1 == "" || o.sha1 == "none" {
|
if o.sha1 == "" || o.sha1 == "none" {
|
||||||
o.sha1 = Info[sha1Key]
|
o.sha1 = Info[sha1Key]
|
||||||
}
|
}
|
||||||
// Remove unverified prefix - see https://www.backblaze.com/b2/docs/uploading.html
|
o.sha1 = cleanSHA1(o.sha1)
|
||||||
// Some tools (eg Cyberduck) use this
|
|
||||||
const unverified = "unverified:"
|
|
||||||
if strings.HasPrefix(o.sha1, unverified) {
|
|
||||||
o.sha1 = o.sha1[len(unverified):]
|
|
||||||
}
|
|
||||||
o.size = Size
|
o.size = Size
|
||||||
// Use the UploadTimestamp if can't get file info
|
// Use the UploadTimestamp if can't get file info
|
||||||
o.modTime = time.Time(UploadTimestamp)
|
o.modTime = time.Time(UploadTimestamp)
|
||||||
|
@ -1653,6 +1663,7 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read
|
||||||
o.sha1 = resp.Header.Get(sha1InfoHeader)
|
o.sha1 = resp.Header.Get(sha1InfoHeader)
|
||||||
fs.Debugf(o, "Reading sha1 from info - %q", o.sha1)
|
fs.Debugf(o, "Reading sha1 from info - %q", o.sha1)
|
||||||
}
|
}
|
||||||
|
o.sha1 = cleanSHA1(o.sha1)
|
||||||
}
|
}
|
||||||
// Don't check length or hash on partial content
|
// Don't check length or hash on partial content
|
||||||
if resp.StatusCode == http.StatusPartialContent {
|
if resp.StatusCode == http.StatusPartialContent {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user