From f4453ff36f542c4fc9fd5b4f6f8b76a253238c67 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 4 Aug 2014 21:02:37 +0200 Subject: [PATCH] Remove Put* functions --- repository.go | 68 ---------------------------------------------- repository_test.go | 19 ++++++------- 2 files changed, 9 insertions(+), 78 deletions(-) diff --git a/repository.go b/repository.go index f6756ef2f..7166461c9 100644 --- a/repository.go +++ b/repository.go @@ -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 diff --git a/repository_test.go b/repository_test.go index aff39d09c..1b5f955a1 100644 --- a/repository_test.go +++ b/repository_test.go @@ -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{}