forked from TrueCloudLab/restic
Remove repository.SaveFrom()
This commit is contained in:
parent
43f7a1fcd9
commit
6fc3590838
6 changed files with 10 additions and 34 deletions
|
@ -1,7 +1,6 @@
|
|||
package restic
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -92,7 +91,7 @@ func (arch *Archiver) isKnownBlob(id backend.ID) bool {
|
|||
}
|
||||
|
||||
// Save stores a blob read from rd in the repository.
|
||||
func (arch *Archiver) Save(t pack.BlobType, id backend.ID, length uint, rd io.Reader) error {
|
||||
func (arch *Archiver) Save(t pack.BlobType, data []byte, id backend.ID) error {
|
||||
debug.Log("Archiver.Save", "Save(%v, %v)\n", t, id.Str())
|
||||
|
||||
if arch.isKnownBlob(id) {
|
||||
|
@ -100,7 +99,7 @@ func (arch *Archiver) Save(t pack.BlobType, id backend.ID, length uint, rd io.Re
|
|||
return nil
|
||||
}
|
||||
|
||||
err := arch.repo.SaveFrom(t, &id, length, rd)
|
||||
_, err := arch.repo.SaveAndEncrypt(t, data, &id)
|
||||
if err != nil {
|
||||
debug.Log("Archiver.Save", "Save(%v, %v): error %v\n", t, id.Str(), err)
|
||||
return err
|
||||
|
@ -160,7 +159,7 @@ func (arch *Archiver) saveChunk(chunk chunker.Chunk, p *Progress, token struct{}
|
|||
defer freeBuf(chunk.Data)
|
||||
|
||||
id := backend.Hash(chunk.Data)
|
||||
err := arch.Save(pack.Data, id, chunk.Length, bytes.NewReader(chunk.Data))
|
||||
err := arch.Save(pack.Data, chunk.Data, id)
|
||||
// TODO handle error
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package restic_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"io"
|
||||
|
@ -108,7 +107,7 @@ func testArchiverDuplication(t *testing.T) {
|
|||
|
||||
buf := make([]byte, 50)
|
||||
|
||||
err := arch.Save(pack.Data, id, uint(len(buf)), bytes.NewReader(buf))
|
||||
err := arch.Save(pack.Data, buf, id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -267,7 +267,7 @@ func testParallelSaveWithDuplication(t *testing.T, seed int) {
|
|||
|
||||
id := backend.Hash(c.Data)
|
||||
time.Sleep(time.Duration(id[0]))
|
||||
err := arch.Save(pack.Data, id, c.Length, bytes.NewReader(c.Data))
|
||||
err := arch.Save(pack.Data, c.Data, id)
|
||||
<-barrier
|
||||
errChan <- err
|
||||
}(c, errChan)
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"restic/backend"
|
||||
|
@ -212,26 +211,6 @@ func (r *Repository) SaveAndEncrypt(t pack.BlobType, data []byte, id *backend.ID
|
|||
return *id, r.savePacker(packer)
|
||||
}
|
||||
|
||||
// SaveFrom encrypts data read from rd and stores it in a pack in the backend as type t.
|
||||
func (r *Repository) SaveFrom(t pack.BlobType, id *backend.ID, length uint, rd io.Reader) error {
|
||||
debug.Log("Repo.SaveFrom", "save id %v (%v, %d bytes)", id.Str(), t, length)
|
||||
if id == nil {
|
||||
return errors.New("id is nil")
|
||||
}
|
||||
|
||||
buf, err := ioutil.ReadAll(rd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = r.SaveAndEncrypt(t, buf, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SaveJSON serialises item as JSON and encrypts and saves it in a pack in the
|
||||
// backend as type t.
|
||||
func (r *Repository) SaveJSON(t pack.BlobType, item interface{}) (backend.ID, error) {
|
||||
|
|
|
@ -117,8 +117,9 @@ func TestSaveFrom(t *testing.T) {
|
|||
id := backend.Hash(data)
|
||||
|
||||
// save
|
||||
err = repo.SaveFrom(pack.Data, &id, uint(size), bytes.NewReader(data))
|
||||
id2, err := repo.SaveAndEncrypt(pack.Data, data, &id)
|
||||
OK(t, err)
|
||||
Equals(t, id, id2)
|
||||
|
||||
OK(t, repo.Flush())
|
||||
|
||||
|
@ -136,7 +137,7 @@ func TestSaveFrom(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func BenchmarkSaveFrom(t *testing.B) {
|
||||
func BenchmarkSaveAndEncrypt(t *testing.B) {
|
||||
repo := SetupRepo()
|
||||
defer TeardownRepo(repo)
|
||||
|
||||
|
@ -153,7 +154,7 @@ func BenchmarkSaveFrom(t *testing.B) {
|
|||
|
||||
for i := 0; i < t.N; i++ {
|
||||
// save
|
||||
err = repo.SaveFrom(pack.Data, &id, uint(size), bytes.NewReader(data))
|
||||
_, err = repo.SaveAndEncrypt(pack.Data, data, &id)
|
||||
OK(t, err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package restic
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
|
@ -105,8 +104,7 @@ func saveFile(t testing.TB, repo *repository.Repository, rd io.Reader) (blobs ba
|
|||
t.Fatalf("unabel to save chunk in repo: %v", err)
|
||||
}
|
||||
|
||||
id := backend.Hash(chunk.Data)
|
||||
err = repo.SaveFrom(pack.Data, &id, uint(len(chunk.Data)), bytes.NewReader(chunk.Data))
|
||||
id, err := repo.SaveAndEncrypt(pack.Data, chunk.Data, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("error saving chunk: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue