From 2fc7abac3529257918a2b1930b6e0f43777f9955 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 27 Feb 2021 23:32:51 +0100 Subject: [PATCH] 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. --- cmd/restic/cmd_copy.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/restic/cmd_copy.go b/cmd/restic/cmd_copy.go index cb8296d4b..d16cd1742 100644 --- a/cmd/restic/cmd_copy.go +++ b/cmd/restic/cmd_copy.go @@ -196,13 +196,16 @@ func copyTree(ctx context.Context, srcRepo restic.Repository, dstRepo restic.Rep // Do we already have this tree blob? 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 { - 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 { - return fmt.Errorf("SaveTree(%v) returned unexpected id %s", tree.ID.Str(), newTreeID.Str()) + + _, _, err = dstRepo.SaveBlob(ctx, restic.TreeBlob, buf, tree.ID, false) + if err != nil { + return fmt.Errorf("SaveBlob(%v) for tree returned error %v", tree.ID.Str(), err) } }