1
0
mirror of https://github.com/restic/restic.git synced 2024-06-26 07:49:01 +02:00

Replace repolitoy.SaveAndEncrypt to SaveBlob()

This commit is contained in:
Alexander Neumann 2016-09-03 20:11:10 +02:00
parent 1cc59010f5
commit fe8c12c798
8 changed files with 23 additions and 11 deletions

View File

@ -7,8 +7,9 @@ import (
"restic/debug" "restic/debug"
"time" "time"
"github.com/restic/chunker"
"restic/errors" "restic/errors"
"github.com/restic/chunker"
) )
// saveTreeJSON stores a tree in the repository. // saveTreeJSON stores a tree in the repository.
@ -58,7 +59,7 @@ func ArchiveReader(repo restic.Repository, p *restic.Progress, rd io.Reader, nam
id := restic.Hash(chunk.Data) id := restic.Hash(chunk.Data)
if !repo.Index().Has(id, restic.DataBlob) { if !repo.Index().Has(id, restic.DataBlob) {
_, err := repo.SaveAndEncrypt(restic.DataBlob, chunk.Data, nil) _, err := repo.SaveBlob(restic.DataBlob, chunk.Data, id)
if err != nil { if err != nil {
return nil, restic.ID{}, err return nil, restic.ID{}, err
} }

View File

@ -98,7 +98,7 @@ func (arch *Archiver) Save(t restic.BlobType, data []byte, id restic.ID) error {
return nil return nil
} }
_, err := arch.repo.SaveAndEncrypt(t, data, &id) _, err := arch.repo.SaveBlob(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

View File

@ -29,7 +29,6 @@ type Repository interface {
SaveJSON(BlobType, interface{}) (ID, error) SaveJSON(BlobType, interface{}) (ID, error)
SaveUnpacked(FileType, []byte) (ID, error) SaveUnpacked(FileType, []byte) (ID, error)
SaveAndEncrypt(BlobType, []byte, *ID) (ID, error)
SaveJSONUnpacked(FileType, interface{}) (ID, error) SaveJSONUnpacked(FileType, interface{}) (ID, error)
LoadJSONUnpacked(FileType, ID, interface{}) error LoadJSONUnpacked(FileType, ID, interface{}) error
@ -37,6 +36,8 @@ type Repository interface {
LoadTree(id ID) (*Tree, error) LoadTree(id ID) (*Tree, error)
LoadDataBlob(id ID, buf []byte) (int, error) LoadDataBlob(id ID, buf []byte) (int, error)
SaveBlob(BlobType, []byte, ID) (ID, error)
} }
// Deleter removes all data stored in a backend/repo. // Deleter removes all data stored in a backend/repo.

View File

@ -64,7 +64,7 @@ func Repack(repo restic.Repository, packs restic.IDSet, keepBlobs restic.BlobSet
} }
plaintext = plaintext[:n] plaintext = plaintext[:n]
_, err = repo.SaveAndEncrypt(entry.Type, plaintext, &entry.ID) _, err = repo.SaveBlob(entry.Type, plaintext, entry.ID)
if err != nil { if err != nil {
return err return err
} }

View File

@ -46,7 +46,7 @@ func createRandomBlobs(t testing.TB, repo restic.Repository, blobs int, pData fl
continue continue
} }
_, err := repo.SaveAndEncrypt(tpe, buf, &id) _, err := repo.SaveBlob(tpe, buf, id)
if err != nil { if err != nil {
t.Fatalf("SaveFrom() error %v", err) t.Fatalf("SaveFrom() error %v", err)
} }

View File

@ -614,3 +614,13 @@ func (r *Repository) LoadDataBlob(id restic.ID, buf []byte) (int, error) {
return len(buf), err return len(buf), err
} }
// SaveBlob saves a blob of type t into the repository. If id is the null id, it
// will be computed and returned.
func (r *Repository) SaveBlob(t restic.BlobType, buf []byte, id restic.ID) (restic.ID, error) {
var i *restic.ID
if !id.IsNull() {
i = &id
}
return r.SaveAndEncrypt(t, buf, i)
}

View File

@ -81,7 +81,7 @@ func TestSave(t *testing.T) {
id := restic.Hash(data) id := restic.Hash(data)
// save // save
sid, err := repo.SaveAndEncrypt(restic.DataBlob, data, nil) sid, err := repo.SaveBlob(restic.DataBlob, data, restic.ID{})
OK(t, err) OK(t, err)
Equals(t, id, sid) Equals(t, id, sid)
@ -117,7 +117,7 @@ func TestSaveFrom(t *testing.T) {
id := restic.Hash(data) id := restic.Hash(data)
// save // save
id2, err := repo.SaveAndEncrypt(restic.DataBlob, data, &id) id2, err := repo.SaveBlob(restic.DataBlob, data, id)
OK(t, err) OK(t, err)
Equals(t, id, id2) Equals(t, id, id2)
@ -156,7 +156,7 @@ func BenchmarkSaveAndEncrypt(t *testing.B) {
for i := 0; i < t.N; i++ { for i := 0; i < t.N; i++ {
// save // save
_, err = repo.SaveAndEncrypt(restic.DataBlob, data, &id) _, err = repo.SaveBlob(restic.DataBlob, data, id)
OK(t, err) OK(t, err)
} }
} }
@ -253,7 +253,7 @@ func saveRandomDataBlobs(t testing.TB, repo restic.Repository, num int, sizeMax
_, err := io.ReadFull(rand.Reader, buf) _, err := io.ReadFull(rand.Reader, buf)
OK(t, err) OK(t, err)
_, err = repo.SaveAndEncrypt(restic.DataBlob, buf, nil) _, err = repo.SaveBlob(restic.DataBlob, buf, restic.ID{})
OK(t, err) OK(t, err)
} }
} }

View File

@ -43,7 +43,7 @@ func (fs fakeFileSystem) saveFile(rd io.Reader) (blobs IDs) {
id := Hash(chunk.Data) id := Hash(chunk.Data)
if !fs.blobIsKnown(id, DataBlob) { if !fs.blobIsKnown(id, DataBlob) {
_, err := fs.repo.SaveAndEncrypt(DataBlob, chunk.Data, &id) _, err := fs.repo.SaveBlob(DataBlob, chunk.Data, id)
if err != nil { if err != nil {
fs.t.Fatalf("error saving chunk: %v", err) fs.t.Fatalf("error saving chunk: %v", err)
} }