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
|
package restic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -92,7 +91,7 @@ func (arch *Archiver) isKnownBlob(id backend.ID) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save stores a blob read from rd in the repository.
|
// 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())
|
debug.Log("Archiver.Save", "Save(%v, %v)\n", t, id.Str())
|
||||||
|
|
||||||
if arch.isKnownBlob(id) {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := arch.repo.SaveFrom(t, &id, length, rd)
|
_, err := arch.repo.SaveAndEncrypt(t, data, &id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug.Log("Archiver.Save", "Save(%v, %v): error %v\n", t, id.Str(), err)
|
debug.Log("Archiver.Save", "Save(%v, %v): error %v\n", t, id.Str(), err)
|
||||||
return err
|
return err
|
||||||
|
@ -160,7 +159,7 @@ func (arch *Archiver) saveChunk(chunk chunker.Chunk, p *Progress, token struct{}
|
||||||
defer freeBuf(chunk.Data)
|
defer freeBuf(chunk.Data)
|
||||||
|
|
||||||
id := backend.Hash(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
|
// TODO handle error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package restic_test
|
package restic_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
@ -108,7 +107,7 @@ func testArchiverDuplication(t *testing.T) {
|
||||||
|
|
||||||
buf := make([]byte, 50)
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,7 +267,7 @@ func testParallelSaveWithDuplication(t *testing.T, seed int) {
|
||||||
|
|
||||||
id := backend.Hash(c.Data)
|
id := backend.Hash(c.Data)
|
||||||
time.Sleep(time.Duration(id[0]))
|
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
|
<-barrier
|
||||||
errChan <- err
|
errChan <- err
|
||||||
}(c, errChan)
|
}(c, errChan)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"restic/backend"
|
"restic/backend"
|
||||||
|
@ -212,26 +211,6 @@ func (r *Repository) SaveAndEncrypt(t pack.BlobType, data []byte, id *backend.ID
|
||||||
return *id, r.savePacker(packer)
|
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
|
// SaveJSON serialises item as JSON and encrypts and saves it in a pack in the
|
||||||
// backend as type t.
|
// backend as type t.
|
||||||
func (r *Repository) SaveJSON(t pack.BlobType, item interface{}) (backend.ID, error) {
|
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)
|
id := backend.Hash(data)
|
||||||
|
|
||||||
// save
|
// save
|
||||||
err = repo.SaveFrom(pack.Data, &id, uint(size), bytes.NewReader(data))
|
id2, err := repo.SaveAndEncrypt(pack.Data, data, &id)
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
Equals(t, id, id2)
|
||||||
|
|
||||||
OK(t, repo.Flush())
|
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()
|
repo := SetupRepo()
|
||||||
defer TeardownRepo(repo)
|
defer TeardownRepo(repo)
|
||||||
|
|
||||||
|
@ -153,7 +154,7 @@ func BenchmarkSaveFrom(t *testing.B) {
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
// save
|
// save
|
||||||
err = repo.SaveFrom(pack.Data, &id, uint(size), bytes.NewReader(data))
|
_, err = repo.SaveAndEncrypt(pack.Data, data, &id)
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package restic
|
package restic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"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)
|
t.Fatalf("unabel to save chunk in repo: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
id := backend.Hash(chunk.Data)
|
id, err := repo.SaveAndEncrypt(pack.Data, chunk.Data, nil)
|
||||||
err = repo.SaveFrom(pack.Data, &id, uint(len(chunk.Data)), bytes.NewReader(chunk.Data))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error saving chunk: %v", err)
|
t.Fatalf("error saving chunk: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue