Skip to content

Commit 0e4361f

Browse files
fix: do not convert existing daglinks
1 parent 04ee50a commit 0e4361f

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/dag-node.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,17 @@ module.exports = class DAGNode {
5050

5151
// ensure links are instances of DAGLink
5252
if (links) {
53-
links.map((l) => {
54-
return {
55-
size: l.size || l.Size,
56-
name: l.name || l.Name,
57-
hash: l.hash || l.Hash
53+
links.forEach((l) => {
54+
if (l.name && typeof l.toJSON === 'function') {
55+
this.links.push(l)
56+
} else {
57+
this.links.push(
58+
new DAGLink(l.Name, l.Size, l.Hash)
59+
)
5860
}
59-
}).forEach((l) => {
60-
this.addRawLink(l)
6161
})
62+
63+
stable.inplace(this.links, linkSort)
6264
}
6365
}
6466

test/dag-node-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ module.exports = function (repo) {
4545
const d2 = new DAGNode(new Buffer('some data'), l2)
4646
expect(d1.toJSON()).to.be.eql(d2.toJSON())
4747
expect(d1.marshal()).to.be.eql(d2.marshal())
48+
expect(d2.links).to.be.eql(l2)
4849
})
4950

5051
it('create an emtpy node', function (done) {

0 commit comments

Comments
 (0)