Fixed issue with retrieving release files

This commit is contained in:
Tim Shannon 2016-04-18 20:31:22 +00:00
parent 7082d69bab
commit a754264a1d
2 changed files with 19 additions and 14 deletions

View File

@ -6,10 +6,8 @@
package datastore package datastore
import ( import (
"bytes"
"encoding/json" "encoding/json"
"errors" "errors"
"io"
"time" "time"
"github.com/boltdb/bolt" "github.com/boltdb/bolt"
@ -77,15 +75,6 @@ func (ds *Store) get(bucket string, key []byte, result interface{}) error {
return ErrNotFound 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) return json.Unmarshal(dsValue, result)
}) })
} }

View File

@ -5,7 +5,9 @@
package datastore package datastore
import ( import (
"bytes"
"encoding/json" "encoding/json"
"io"
"time" "time"
"github.com/boltdb/bolt" "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 // ReleaseFile returns a specific file from a release for the given file key
func (ds *Store) ReleaseFile(fileKey TimeKey) ([]byte, error) { func (ds *Store) ReleaseFile(fileKey TimeKey) ([]byte, error) {
var fileData []byte var fileData bytes.Buffer
err := ds.get(bucketFiles, fileKey.Bytes(), fileData)
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 { if err != nil {
return nil, err return nil, err
} }
return fileData, nil return fileData.Bytes(), nil
} }
// Release gets the release record for a specific version // Release gets the release record for a specific version