2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-23 03:18:55 +00: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"
"time"
"github.com/restic/chunker"
"restic/errors"
"github.com/restic/chunker"
)
// 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)
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 {
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
}
_, err := arch.repo.SaveAndEncrypt(t, data, &id)
_, err := arch.repo.SaveBlob(t, data, id)
if err != nil {
debug.Log("Archiver.Save", "Save(%v, %v): error %v\n", t, id.Str(), err)
return err

View File

@ -29,7 +29,6 @@ type Repository interface {
SaveJSON(BlobType, interface{}) (ID, error)
SaveUnpacked(FileType, []byte) (ID, error)
SaveAndEncrypt(BlobType, []byte, *ID) (ID, error)
SaveJSONUnpacked(FileType, interface{}) (ID, error)
LoadJSONUnpacked(FileType, ID, interface{}) error
@ -37,6 +36,8 @@ type Repository interface {
LoadTree(id ID) (*Tree, error)
LoadDataBlob(id ID, buf []byte) (int, error)
SaveBlob(BlobType, []byte, ID) (ID, error)
}
// 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]
_, err = repo.SaveAndEncrypt(entry.Type, plaintext, &entry.ID)
_, err = repo.SaveBlob(entry.Type, plaintext, entry.ID)
if err != nil {
return err
}

View File

@ -46,7 +46,7 @@ func createRandomBlobs(t testing.TB, repo restic.Repository, blobs int, pData fl
continue
}
_, err := repo.SaveAndEncrypt(tpe, buf, &id)
_, err := repo.SaveBlob(tpe, buf, id)
if err != nil {
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
}
// 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)
// save
sid, err := repo.SaveAndEncrypt(restic.DataBlob, data, nil)
sid, err := repo.SaveBlob(restic.DataBlob, data, restic.ID{})
OK(t, err)
Equals(t, id, sid)
@ -117,7 +117,7 @@ func TestSaveFrom(t *testing.T) {
id := restic.Hash(data)
// save
id2, err := repo.SaveAndEncrypt(restic.DataBlob, data, &id)
id2, err := repo.SaveBlob(restic.DataBlob, data, id)
OK(t, err)
Equals(t, id, id2)
@ -156,7 +156,7 @@ func BenchmarkSaveAndEncrypt(t *testing.B) {
for i := 0; i < t.N; i++ {
// save
_, err = repo.SaveAndEncrypt(restic.DataBlob, data, &id)
_, err = repo.SaveBlob(restic.DataBlob, data, id)
OK(t, err)
}
}
@ -253,7 +253,7 @@ func saveRandomDataBlobs(t testing.TB, repo restic.Repository, num int, sizeMax
_, err := io.ReadFull(rand.Reader, buf)
OK(t, err)
_, err = repo.SaveAndEncrypt(restic.DataBlob, buf, nil)
_, err = repo.SaveBlob(restic.DataBlob, buf, restic.ID{})
OK(t, err)
}
}

View File

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