mirror of
https://github.com/octoleo/restic.git
synced 2025-01-25 16:18:34 +00:00
Remove usage of CreateEncryptedBlob()
This commit is contained in:
parent
01e40e62bf
commit
cfdd3a853d
@ -594,33 +594,14 @@ func ConvertIndex(repo *Repository, id backend.ID) (backend.ID, error) {
|
|||||||
return id, err
|
return id, err
|
||||||
}
|
}
|
||||||
|
|
||||||
blob, err := repo.CreateEncryptedBlob(backend.Index)
|
buf := bytes.NewBuffer(nil)
|
||||||
if err != nil {
|
|
||||||
return id, err
|
|
||||||
}
|
|
||||||
|
|
||||||
idx.supersedes = backend.IDs{id}
|
idx.supersedes = backend.IDs{id}
|
||||||
|
|
||||||
err = idx.Encode(blob)
|
err = idx.Encode(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug.Log("ConvertIndex", "oldIdx.Encode() returned error: %v", err)
|
debug.Log("ConvertIndex", "oldIdx.Encode() returned error: %v", err)
|
||||||
return id, err
|
return id, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = blob.Close()
|
return repo.SaveUnpacked(backend.Index, buf.Bytes())
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
@ -271,13 +271,19 @@ func (r *Repository) SaveJSONUnpacked(t backend.Type, item interface{}) (backend
|
|||||||
return backend.ID{}, fmt.Errorf("json.Encode: %v", err)
|
return backend.ID{}, fmt.Errorf("json.Encode: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ciphertext := make([]byte, len(plaintext)+crypto.Extension)
|
return r.SaveUnpacked(t, plaintext)
|
||||||
ciphertext, err = crypto.Encrypt(r.key, ciphertext, 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 {
|
if err != nil {
|
||||||
return backend.ID{}, err
|
return backend.ID{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
id := backend.Hash(ciphertext)
|
id = backend.Hash(ciphertext)
|
||||||
h := backend.Handle{Type: t, Name: id.String()}
|
h := backend.Handle{Type: t, Name: id.String()}
|
||||||
|
|
||||||
err = r.be.Save(h, ciphertext)
|
err = r.be.Save(h, ciphertext)
|
||||||
@ -377,26 +383,16 @@ func (bw *BlobWriter) ID() backend.ID {
|
|||||||
return bw.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) {
|
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 {
|
if err != nil {
|
||||||
return backend.ID{}, err
|
return backend.ID{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = index.Finalize(blob)
|
return repo.SaveUnpacked(backend.Index, buf.Bytes())
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// saveIndex saves all indexes in the backend.
|
// saveIndex saves all indexes in the backend.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user