2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-22 04:45:15 +00:00

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) 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. // Construct directory for given Type.
func (r *Repository) dir(t Type) string { func (r *Repository) dir(t Type) string {
switch t { switch t {
@ -166,45 +137,6 @@ func (r *Repository) filename(t Type, id ID) string {
return path.Join(r.dir(t), 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. // Test returns true if the given ID exists in the repository.
func (r *Repository) Test(t Type, id ID) (bool, error) { func (r *Repository) Test(t Type, id ID) (bool, error) {
// try to open file // try to open file

View File

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