Remove Put* functions

This commit is contained in:
Alexander Neumann 2014-08-04 21:02:37 +02:00
parent b3c2d82331
commit f4453ff36f
2 changed files with 9 additions and 78 deletions

View File

@ -120,35 +120,6 @@ func (r *Repository) renameFile(file *os.File, t Type, id ID) error {
return os.Rename(file.Name(), filename)
}
// Put saves content and returns the ID.
func (r *Repository) Put(t Type, reader io.Reader) (ID, error) {
// save contents to tempfile, hash while writing
file, err := r.tempFile()
if err != nil {
return nil, err
}
rd := NewHashingReader(reader, r.hash)
_, err = io.Copy(file, rd)
if err != nil {
return nil, err
}
err = file.Close()
if err != nil {
return nil, err
}
// move file to final name using hash of contents
id := ID(rd.Hash())
err = r.renameFile(file, t, id)
if err != nil {
return nil, err
}
return id, nil
}
// Construct directory for given Type.
func (r *Repository) dir(t Type) string {
switch t {
@ -166,45 +137,6 @@ func (r *Repository) filename(t Type, id ID) string {
return path.Join(r.dir(t), id.String())
}
// PutFile saves a file's content to the repository and returns the ID.
func (r *Repository) PutFile(path string) (ID, error) {
f, err := os.Open(path)
defer f.Close()
if err != nil {
return nil, err
}
return r.Put(TYPE_BLOB, f)
}
// PutRaw saves a []byte's content to the repository and returns the ID.
func (r *Repository) PutRaw(t Type, buf []byte) (ID, error) {
// save contents to tempfile, hash while writing
file, err := r.tempFile()
if err != nil {
return nil, err
}
wr := NewHashingWriter(file, r.hash)
_, err = wr.Write(buf)
if err != nil {
return nil, err
}
err = file.Close()
if err != nil {
return nil, err
}
// move file to final name using hash of contents
id := ID(wr.Hash())
err = r.renameFile(file, t, id)
if err != nil {
return nil, err
}
return id, nil
}
// Test returns true if the given ID exists in the repository.
func (r *Repository) Test(t Type, id ID) (bool, error) {
// try to open file

View File

@ -6,7 +6,6 @@ import (
"io/ioutil"
"os"
"sort"
"strings"
"testing"
"github.com/fd0/khepri"
@ -76,8 +75,16 @@ func TestRepository(t *testing.T) {
// add files
for _, test := range TestStrings {
// store string in repository
id, err := repo.Put(test.t, strings.NewReader(test.data))
obj, err := repo.NewObject(test.t)
ok(t, err)
_, err = obj.Write([]byte(test.data))
ok(t, err)
err = obj.Close()
ok(t, err)
id := obj.ID()
equals(t, test.id, id.String())
// try to get it out again
@ -90,14 +97,6 @@ func TestRepository(t *testing.T) {
equals(t, test.data, string(buf))
}
// add buffer
for _, test := range TestStrings {
// store buf in repository
id, err := repo.PutRaw(test.t, []byte(test.data))
ok(t, err)
equals(t, test.id, id.String())
}
// list ids
for _, tpe := range []khepri.Type{khepri.TYPE_BLOB, khepri.TYPE_REF} {
IDs := khepri.IDs{}