2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-02 11:46:36 +00:00

Remove usage of CreateEncryptedBlob()

This commit is contained in:
Alexander Neumann 2016-01-24 18:52:11 +01:00
parent 01e40e62bf
commit cfdd3a853d
2 changed files with 17 additions and 40 deletions

View File

@ -594,33 +594,14 @@ func ConvertIndex(repo *Repository, id backend.ID) (backend.ID, error) {
return id, err
}
blob, err := repo.CreateEncryptedBlob(backend.Index)
if err != nil {
return id, err
}
buf := bytes.NewBuffer(nil)
idx.supersedes = backend.IDs{id}
err = idx.Encode(blob)
err = idx.Encode(buf)
if err != nil {
debug.Log("ConvertIndex", "oldIdx.Encode() returned error: %v", err)
return id, err
}
err = blob.Close()
if err != nil {
debug.Log("ConvertIndex", "blob.Close() returned error: %v", err)
return id, err
}
newID := blob.ID()
debug.Log("ConvertIndex", "index %v converted to new format as %v", id.Str(), newID.Str())
err = repo.be.Remove(backend.Index, id.String())
if err != nil {
debug.Log("ConvertIndex", "backend.Remove(%v) returned error: %v", id.Str(), err)
return id, err
}
return newID, nil
return repo.SaveUnpacked(backend.Index, buf.Bytes())
}

View File

@ -271,13 +271,19 @@ func (r *Repository) SaveJSONUnpacked(t backend.Type, item interface{}) (backend
return backend.ID{}, fmt.Errorf("json.Encode: %v", err)
}
ciphertext := make([]byte, len(plaintext)+crypto.Extension)
ciphertext, err = crypto.Encrypt(r.key, ciphertext, plaintext)
return r.SaveUnpacked(t, plaintext)
}
// SaveUnpacked encrypts data and stores it in the backend. Returned is the
// storage hash.
func (r *Repository) SaveUnpacked(t backend.Type, p []byte) (id backend.ID, err error) {
ciphertext := make([]byte, len(p)+crypto.Extension)
ciphertext, err = r.Encrypt(ciphertext, p)
if err != nil {
return backend.ID{}, err
}
id := backend.Hash(ciphertext)
id = backend.Hash(ciphertext)
h := backend.Handle{Type: t, Name: id.String()}
err = r.be.Save(h, ciphertext)
@ -377,26 +383,16 @@ func (bw *BlobWriter) ID() backend.ID {
return bw.id
}
// SaveIndex saves an index to repo's backend.
// SaveIndex saves an index in the repository.
func SaveIndex(repo *Repository, index *Index) (backend.ID, error) {
blob, err := repo.CreateEncryptedBlob(backend.Index)
buf := bytes.NewBuffer(nil)
err := index.Finalize(buf)
if err != nil {
return backend.ID{}, err
}
err = index.Finalize(blob)
if err != nil {
return backend.ID{}, err
}
err = blob.Close()
if err != nil {
return backend.ID{}, err
}
sid := blob.ID()
err = index.SetID(sid)
return sid, err
return repo.SaveUnpacked(backend.Index, buf.Bytes())
}
// saveIndex saves all indexes in the backend.