Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
fix: named links should return the CID
Browse files Browse the repository at this point in the history
Prior to this change, named links didn't return the CID they are
pointing to, but the DAGLink. This made proper named links traversal
as it is done by UnixFSv1 impossible.

Thanks @alanshaw for finding and providing a solution to this bug.
  • Loading branch information
vmx committed May 20, 2019
1 parent 87a4703 commit ee96d28
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/dag-node/addNamedLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const addNamedLink = (object, name, position) => {
Object.defineProperty(object, name, {
enumerable: true,
configurable: true,
get: () => object._links[position]
get: () => object._links[position].Hash
})
}

Expand Down
16 changes: 5 additions & 11 deletions test/resolver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('IPLD Format resolver (local)', () => {

it('links by name', () => {
const result = resolver.resolve(linksNodeBlob, 'named link')
expect(result.value.Hash.equals(links[1].Hash)).to.be.true()
expect(result.value.equals(links[1].Hash)).to.be.true()
expect(result.remainderPath).to.eql('')
})

Expand Down Expand Up @@ -128,15 +128,15 @@ describe('IPLD Format resolver (local)', () => {
})

it('yield remainderPath if impossible to resolve through named link (a)', () => {
const result = resolver.resolve(linksNodeBlob, 'named link/Hash/Data')
const result = resolver.resolve(linksNodeBlob, 'named link/Data')
expect(result.value.equals(
new CID('QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V')
)).to.be.true()
expect(result.remainderPath).to.equal('Data')
})

it('yield remainderPath if impossible to resolve through named link (b)', () => {
const result = resolver.resolve(linksNodeBlob, 'named link/Hash/Links/0/Hash/Data')
const result = resolver.resolve(linksNodeBlob, 'named link/Links/0/Hash/Data')
expect(result.value.equals(
new CID('QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V')
)).to.be.true()
Expand All @@ -158,10 +158,7 @@ describe('IPLD Format resolver (local)', () => {
'Links/1/Tsize',
'Links/1/Hash',
'Data',
'named link',
'named link/Name',
'named link/Tsize',
'named link/Hash'
'named link'
])
})
})
Expand Down Expand Up @@ -210,10 +207,7 @@ describe('IPLD Format resolver (local)', () => {
'Links/1/Tsize',
'Links/1/Hash',
'Data',
'named link',
'named link/Name',
'named link/Tsize',
'named link/Hash'
'named link'
])
})
})
Expand Down

0 comments on commit ee96d28

Please sign in to comment.