From a754264a1da5720d98d3ed4e82ab3c1f0467b3fd Mon Sep 17 00:00:00 2001 From: Tim Shannon Date: Mon, 18 Apr 2016 20:31:22 +0000 Subject: [PATCH] Fixed issue with retrieving release files --- datastore/ds.go | 11 ----------- datastore/releases.go | 22 +++++++++++++++++++--- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/datastore/ds.go b/datastore/ds.go index bf5f817..d0a0a8c 100644 --- a/datastore/ds.go +++ b/datastore/ds.go @@ -6,10 +6,8 @@ package datastore import ( - "bytes" "encoding/json" "errors" - "io" "time" "github.com/boltdb/bolt" @@ -77,15 +75,6 @@ func (ds *Store) get(bucket string, key []byte, result interface{}) error { return ErrNotFound } - if value, ok := result.([]byte); ok { - buff := bytes.NewBuffer(value) - _, err := io.Copy(buff, bytes.NewReader(dsValue)) - if err != nil { - return err - } - return nil - } - return json.Unmarshal(dsValue, result) }) } diff --git a/datastore/releases.go b/datastore/releases.go index fc481ee..483170b 100644 --- a/datastore/releases.go +++ b/datastore/releases.go @@ -5,7 +5,9 @@ package datastore import ( + "bytes" "encoding/json" + "io" "time" "github.com/boltdb/bolt" @@ -52,13 +54,27 @@ func (ds *Store) AddRelease(version, fileName string, fileData []byte) error { // ReleaseFile returns a specific file from a release for the given file key func (ds *Store) ReleaseFile(fileKey TimeKey) ([]byte, error) { - var fileData []byte - err := ds.get(bucketFiles, fileKey.Bytes(), fileData) + var fileData bytes.Buffer + + err := ds.bolt.View(func(tx *bolt.Tx) error { + dsValue := tx.Bucket([]byte(bucketFiles)).Get(fileKey.Bytes()) + + if dsValue == nil { + return ErrNotFound + } + + _, err := io.Copy(&fileData, bytes.NewReader(dsValue)) + if err != nil { + return err + } + return nil + }) + if err != nil { return nil, err } - return fileData, nil + return fileData.Bytes(), nil } // Release gets the release record for a specific version