From be768d01a2f02bcace59823e01e6aad421bbdfd6 Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Fri, 27 Feb 2015 12:18:08 -0800 Subject: [PATCH] Seek to beginning for tempbuffer --- pkg/storage/donut/v1/donut.go | 18 ++++++++++++------ pkg/storage/donut/v1/donut_test.go | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pkg/storage/donut/v1/donut.go b/pkg/storage/donut/v1/donut.go index a6f93ae0a..7645d642b 100644 --- a/pkg/storage/donut/v1/donut.go +++ b/pkg/storage/donut/v1/donut.go @@ -22,6 +22,8 @@ import ( "encoding/gob" "errors" "io" + "io/ioutil" + "os" "sync" "github.com/minio-io/minio/pkg/storage/erasure" @@ -206,26 +208,30 @@ func (donut *Donut) Write(gobHeader GobHeader, object io.Reader) error { BlockEnd: MagicINIM, } - var tempBuffer bytes.Buffer - + tempBuffer, err := ioutil.TempFile(os.TempDir(), "minio-staging") + if err != nil { + return err + } + defer os.Remove(tempBuffer.Name()) // write header - if err := donut.WriteBegin(&tempBuffer, donutFormat); err != nil { + if err := donut.WriteBegin(tempBuffer, donutFormat); err != nil { return err } // write data - if err := donut.WriteData(&tempBuffer, donutFormat); err != nil { + if err := donut.WriteData(tempBuffer, donutFormat); err != nil { return err } // write footer crc - if err := donut.WriteEnd(&tempBuffer, donutFormat); err != nil { + if err := donut.WriteEnd(tempBuffer, donutFormat); err != nil { return err } // write footer donut.file.Seek(0, 2) - io.Copy(donut.file, &tempBuffer) + tempBuffer.Seek(0, 0) + io.Copy(donut.file, tempBuffer) return nil } diff --git a/pkg/storage/donut/v1/donut_test.go b/pkg/storage/donut/v1/donut_test.go index 5a76f47ac..54a4149f1 100644 --- a/pkg/storage/donut/v1/donut_test.go +++ b/pkg/storage/donut/v1/donut_test.go @@ -19,7 +19,6 @@ package v1 import ( "bytes" . "gopkg.in/check.v1" - "io" "io/ioutil" "os" "testing" @@ -32,10 +31,11 @@ type MySuite struct{} var _ = Suite(&MySuite{}) func (s *MySuite) TestAPISuite(c *C) { - var b io.ReadWriteSeeker + //var b io.ReadWriteSeeker var o bytes.Buffer b, err := ioutil.TempFile(os.TempDir(), "minio-donut-test") + defer os.RemoveAll(b.Name()) c.Assert(err, IsNil) donut := New(b)