From a0ec21975d9a20149ac29c1b71679cdbccab6568 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 11 Dec 2014 19:43:58 -0800 Subject: [PATCH] Calculate md5sum for each object --- pkgs/storage/encodedstorage/encoded_storage.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkgs/storage/encodedstorage/encoded_storage.go b/pkgs/storage/encodedstorage/encoded_storage.go index 089126419..2909ad49e 100644 --- a/pkgs/storage/encodedstorage/encoded_storage.go +++ b/pkgs/storage/encodedstorage/encoded_storage.go @@ -2,6 +2,7 @@ package encodedstorage import ( "bytes" + "crypto/md5" "encoding/gob" "errors" "io" @@ -27,7 +28,7 @@ type encodedStorage struct { type StorageEntry struct { Path string - Md5sum string + Md5sum []byte Blocks []StorageBlockEntry Encoderparams erasure.EncoderParams } @@ -109,7 +110,7 @@ func (eStorage *encodedStorage) Put(objectPath string, object io.Reader) error { encoder := erasure.NewEncoder(encoderParameters) entry := StorageEntry{ Path: objectPath, - Md5sum: "md5sum", + Md5sum: nil, Blocks: make([]StorageBlockEntry, 0), Encoderparams: erasure.EncoderParams{ K: eStorage.K, @@ -117,10 +118,14 @@ func (eStorage *encodedStorage) Put(objectPath string, object io.Reader) error { Technique: erasure.CAUCHY, }, } + // allocate md5 + hash := md5.New() i := 0 // encode for chunk := range chunks { if chunk.Err == nil { + // md5sum on chunk + hash.Write(chunk.Data) // encode each blocks, length := encoder.Encode(chunk.Data) // store each @@ -140,6 +145,7 @@ func (eStorage *encodedStorage) Put(objectPath string, object io.Reader) error { } i++ } + entry.Md5sum = hash.Sum(nil) eStorage.objects[objectPath] = entry var gobBuffer bytes.Buffer gobEncoder := gob.NewEncoder(&gobBuffer)