mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 16:34:30 +01:00
b2: Fix download of large files - fixes #678
Large files were failing to download with an sha1 mismatch error. Correct this by making sure we use the sha1 read from the info rather than the header.
This commit is contained in:
parent
0c6990bc95
commit
b3d0848d09
11
b2/b2.go
11
b2/b2.go
@ -35,6 +35,7 @@ const (
|
|||||||
timeHeader = headerPrefix + timeKey
|
timeHeader = headerPrefix + timeKey
|
||||||
sha1Key = "large_file_sha1"
|
sha1Key = "large_file_sha1"
|
||||||
sha1Header = "X-Bz-Content-Sha1"
|
sha1Header = "X-Bz-Content-Sha1"
|
||||||
|
sha1InfoHeader = headerPrefix + sha1Key
|
||||||
testModeHeader = "X-Bz-Test-Mode"
|
testModeHeader = "X-Bz-Test-Mode"
|
||||||
retryAfterHeader = "Retry-After"
|
retryAfterHeader = "Retry-After"
|
||||||
minSleep = 10 * time.Millisecond
|
minSleep = 10 * time.Millisecond
|
||||||
@ -1066,7 +1067,7 @@ func (file *openFile) Close() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check the SHA1
|
// Check the SHA1
|
||||||
receivedSHA1 := file.resp.Header.Get(sha1Header)
|
receivedSHA1 := file.o.sha1
|
||||||
calculatedSHA1 := fmt.Sprintf("%x", file.hash.Sum(nil))
|
calculatedSHA1 := fmt.Sprintf("%x", file.hash.Sum(nil))
|
||||||
if receivedSHA1 != calculatedSHA1 {
|
if receivedSHA1 != calculatedSHA1 {
|
||||||
return errors.Errorf("object corrupted on transfer - SHA1 mismatch (want %q got %q)", receivedSHA1, calculatedSHA1)
|
return errors.Errorf("object corrupted on transfer - SHA1 mismatch (want %q got %q)", receivedSHA1, calculatedSHA1)
|
||||||
@ -1106,8 +1107,16 @@ func (o *Object) Open() (in io.ReadCloser, err error) {
|
|||||||
_ = resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// Read sha1 from header if it isn't set
|
||||||
if o.sha1 == "" {
|
if o.sha1 == "" {
|
||||||
o.sha1 = resp.Header.Get(sha1Header)
|
o.sha1 = resp.Header.Get(sha1Header)
|
||||||
|
fs.Debug(o, "Reading sha1 from header - %q", o.sha1)
|
||||||
|
// if sha1 header is "none" (in big files), then need
|
||||||
|
// to read it from the metadata
|
||||||
|
if o.sha1 == "none" {
|
||||||
|
o.sha1 = resp.Header.Get(sha1InfoHeader)
|
||||||
|
fs.Debug(o, "Reading sha1 from info - %q", o.sha1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return newOpenFile(o, resp), nil
|
return newOpenFile(o, resp), nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user