From f7fd526b283893794b7274176a655bfb197c6b0c Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 12 Mar 2015 02:11:04 -0700 Subject: [PATCH] Cosmetic changes --- pkg/storage/donut/fragment/fragment1/fragment.go | 7 +++---- pkg/storage/donut/object/objectv1/objectv1_test.go | 9 ++++----- pkg/storage/{storage_bucket_date.go => storage_date.go} | 0 3 files changed, 7 insertions(+), 9 deletions(-) rename pkg/storage/{storage_bucket_date.go => storage_date.go} (100%) diff --git a/pkg/storage/donut/fragment/fragment1/fragment.go b/pkg/storage/donut/fragment/fragment1/fragment.go index 4481dba7c..79920417a 100644 --- a/pkg/storage/donut/fragment/fragment1/fragment.go +++ b/pkg/storage/donut/fragment/fragment1/fragment.go @@ -169,8 +169,8 @@ func Read(reader io.Reader) (io.Reader, error) { footerBuffer := make([]byte, 80) reader.Read(footerBuffer) expectedCrc := binary.LittleEndian.Uint32(footerBuffer[:4]) - actualCrc := crc32c.Sum32(footerBuffer[4:]) + if expectedCrc != actualCrc { // TODO perhaps we should return data and still report error? return nil, errors.New("Expected CRC doesn't match for footer") @@ -195,16 +195,14 @@ func ReadHeader(reader io.Reader) (header DonutFrameHeader, err error) { if headerLength != 32 { return header, errors.New("EOF found while reading donut header") } + actualCrc := crc32c.Sum32(headerSlice[:24]) - expectedCrc := binary.LittleEndian.Uint32(headerSlice[24:28]) - if actualCrc != expectedCrc { return header, errors.New("CRC for donut did not match") } err = binary.Read(bytes.NewBuffer(headerSlice[0:24]), binary.LittleEndian, &header) - return header, nil } @@ -213,6 +211,7 @@ type checksumValue struct { err error } +// calculate sha512 over channel func generateChecksum(reader io.Reader, c chan<- checksumValue) { checksum, err := sha512.SumStream(reader) result := checksumValue{ diff --git a/pkg/storage/donut/object/objectv1/objectv1_test.go b/pkg/storage/donut/object/objectv1/objectv1_test.go index f8c52392c..b625c881f 100644 --- a/pkg/storage/donut/object/objectv1/objectv1_test.go +++ b/pkg/storage/donut/object/objectv1/objectv1_test.go @@ -37,11 +37,10 @@ var _ = Suite(&MySuite{}) func (s *MySuite) TestObjectV1ReadWrite(c *C) { var buffer bytes.Buffer - data := "Hello, World" + data := []byte("Hello, World") hash := md5.New() - hash.Sum([]byte(data)) - sum := hash.Sum(nil) + sum := hash.Sum(data) objectMetadata := ObjectMetadata{ Bucket: "bucket", @@ -56,7 +55,7 @@ func (s *MySuite) TestObjectV1ReadWrite(c *C) { Length: uint64(len(sum)), } - err := Write(&buffer, objectMetadata, bytes.NewBufferString(data)) + err := Write(&buffer, objectMetadata, bytes.NewBuffer(data)) c.Assert(err, IsNil) versionBuffer := make([]byte, 4) @@ -73,5 +72,5 @@ func (s *MySuite) TestObjectV1ReadWrite(c *C) { _, err = io.Copy(&actualData, &buffer) c.Assert(err, IsNil) - c.Assert(actualData.Bytes(), DeepEquals, []byte(data)) + c.Assert(actualData.Bytes(), DeepEquals, data) } diff --git a/pkg/storage/storage_bucket_date.go b/pkg/storage/storage_date.go similarity index 100% rename from pkg/storage/storage_bucket_date.go rename to pkg/storage/storage_date.go