gs/swift: calculate md5 content hash for upload

This commit is contained in:
Michael Eischer 2020-12-19 12:49:58 +01:00
parent 1d3e99f475
commit a009b39e4c
2 changed files with 7 additions and 3 deletions

View file

@ -2,6 +2,8 @@ package swift
import (
"context"
"crypto/md5"
"encoding/hex"
"fmt"
"hash"
"io"
@ -118,7 +120,7 @@ func (be *beSwift) Location() string {
// Hasher may return a hash function for calculating a content hash for the backend
func (be *beSwift) Hasher() hash.Hash {
return nil
return md5.New()
}
// Load runs fn with a reader that yields the contents of the file at h at the
@ -184,7 +186,7 @@ func (be *beSwift) Save(ctx context.Context, h restic.Handle, rd restic.RewindRe
debug.Log("PutObject(%v, %v, %v)", be.container, objName, encoding)
hdr := swift.Headers{"Content-Length": strconv.FormatInt(rd.Length(), 10)}
_, err := be.conn.ObjectPut(be.container, objName, rd, true, "", encoding, hdr)
_, err := be.conn.ObjectPut(be.container, objName, rd, true, hex.EncodeToString(rd.Hash()), encoding, hdr)
// swift does not return the upload length
debug.Log("%v, err %#v", objName, err)