2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 10:58:55 +00:00

copy: copy raw bytes of tree blobs

This avoids problems when for some reason the JSON encoding changes.
This also ensures forward compatibility with future restic versions
which might e.g. add new fields to the tree metadata.
This commit is contained in:
Michael Eischer 2021-02-27 23:32:51 +01:00
parent d686fa25de
commit 2fc7abac35

View File

@ -196,13 +196,16 @@ func copyTree(ctx context.Context, srcRepo restic.Repository, dstRepo restic.Rep
// Do we already have this tree blob? // Do we already have this tree blob?
if !dstRepo.Index().Has(restic.BlobHandle{ID: tree.ID, Type: restic.TreeBlob}) { if !dstRepo.Index().Has(restic.BlobHandle{ID: tree.ID, Type: restic.TreeBlob}) {
newTreeID, err := dstRepo.SaveTree(ctx, tree.Tree) // copy raw tree bytes to avoid problems if the serialization changes
var err error
buf, err = srcRepo.LoadBlob(ctx, restic.TreeBlob, tree.ID, buf)
if err != nil { if err != nil {
return fmt.Errorf("SaveTree(%v) returned error %v", tree.ID.Str(), err) return fmt.Errorf("LoadBlob(%v) for tree returned error %v", tree.ID, err)
} }
// Assurance only.
if newTreeID != tree.ID { _, _, err = dstRepo.SaveBlob(ctx, restic.TreeBlob, buf, tree.ID, false)
return fmt.Errorf("SaveTree(%v) returned unexpected id %s", tree.ID.Str(), newTreeID.Str()) if err != nil {
return fmt.Errorf("SaveBlob(%v) for tree returned error %v", tree.ID.Str(), err)
} }
} }