mirror of
https://github.com/restic/restic.git
synced 2026-06-10 19:09:44 +00:00
data: fix invalid trees used in test cases
data.TestCreateSnapshot which is used in particular by TestFindUsedBlobs and TestFindUsedBlobs could generate trees with duplicate file names. This is invalid and going forward will result in an error.
This commit is contained in:
@@ -127,6 +127,10 @@ func LoadTree(ctx context.Context, r restic.BlobLoader, id restic.ID) (*Tree, er
|
||||
// checked against the index. The tree is only stored when the index does not
|
||||
// contain the ID.
|
||||
func SaveTree(ctx context.Context, r restic.BlobSaver, t *Tree) (restic.ID, error) {
|
||||
if t.Nodes == nil {
|
||||
// serialize an empty tree as `{"nodes":[]}` to be consistent with TreeJSONBuilder
|
||||
t.Nodes = make([]*Node, 0)
|
||||
}
|
||||
buf, err := json.Marshal(t)
|
||||
if err != nil {
|
||||
return restic.ID{}, errors.Wrap(err, "MarshalJSON")
|
||||
|
||||
Reference in New Issue
Block a user