gs/swift: calculate md5 content hash for upload
This commit is contained in:
parent
1d3e99f475
commit
a009b39e4c
2 changed files with 7 additions and 3 deletions
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue