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

@@ -3,6 +3,7 @@ package gs
import (
"context"
"crypto/md5"
"hash"
"io"
"net/http"
@@ -191,7 +192,7 @@ func (be *Backend) Location() string {
// Hasher may return a hash function for calculating a content hash for the backend
func (be *Backend) Hasher() hash.Hash {
return nil
return md5.New()
}
// Path returns the path in the bucket that is used for this backend.
@@ -240,6 +241,7 @@ func (be *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindRe
// uploads are not providing significant benefit anyways.
w := be.bucket.Object(objName).NewWriter(ctx)
w.ChunkSize = 0
w.MD5 = rd.Hash()
wbytes, err := io.Copy(w, rd)
cerr := w.Close()
if err == nil {