1
0
mirror of https://github.com/minio/mc.git synced 2025-11-16 11:02:34 +03:00

Filesystem now calculates md5sum and returns

This commit is contained in:
Harshavardhana
2015-04-24 20:15:57 -07:00
parent f8ac1b96d1
commit 9fb94c72a1
5 changed files with 113 additions and 19 deletions

View File

@@ -19,6 +19,9 @@
package fs
import (
"bytes"
"crypto/md5"
"encoding/hex"
"errors"
"io"
"os"
@@ -57,13 +60,30 @@ func (f *fsClient) Put(md5HexString string, size int64) (io.WriteCloser, error)
blockingWriter.Release(err)
return
}
_, err = io.CopyN(fs, r, size)
// calculate md5 to verify - incoming md5
h := md5.New()
mw := io.MultiWriter(fs, h)
_, err = io.CopyN(mw, r, size)
if err != nil {
err := iodine.New(err, nil)
r.CloseWithError(err)
blockingWriter.Release(err)
return
}
expectedMD5, err := hex.DecodeString(md5HexString)
if err != nil {
err := iodine.New(err, nil)
r.CloseWithError(err)
blockingWriter.Release(err)
return
}
if !bytes.Equal(expectedMD5, h.Sum(nil)) {
err := iodine.New(errors.New("md5sum mismatch"), nil)
r.CloseWithError(err)
blockingWriter.Release(err)
return
}
blockingWriter.Release(nil)
r.Close()
}()