Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 399ce36

Browse files
fix: make "ipfs resolve" cli command recursive by default (#3707)
This changes the default behaviour of the `jsipfs resolve` cli command to be recursive by default. Closes #3692. ```shell # in packages/ipfs node src/cli.js resolve /ipns/ipfs.io /ipfs/bafybeiagozluzfopjadeigrjlsmktseozde2xc5prvighob7452imnk76a ``` BREAKING CHANGE: resolve is now recursive by default Co-authored-by: Alex Potsides <[email protected]>
1 parent d13d15f commit 399ce36

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

packages/interface-ipfs-core/src/miscellaneous/resolve.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ module.exports = (common, options) => {
8585
expect(isIpfs.ipfsPath(resolved)).to.be.true()
8686
})
8787

88-
it('should resolve IPNS link recursively', async function () {
88+
it('should resolve IPNS link recursively by default', async function () {
8989
this.timeout(20 * 1000)
9090
// webworkers are not dialable because webrtc is not available
9191
const node = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api
@@ -96,8 +96,23 @@ module.exports = (common, options) => {
9696
await ipfs.name.publish(path, { allowOffline: true })
9797
await ipfs.name.publish(`/ipns/${ipfs.peerId.id}`, { allowOffline: true, key: 'key-name', resolve: false })
9898

99-
return expect(await ipfs.resolve(`/ipns/${keyId}`, { recursive: true }))
99+
return expect(await ipfs.resolve(`/ipns/${keyId}`))
100100
.to.eq(`/ipfs/${path}`)
101101
})
102+
103+
it('should resolve IPNS link non-recursively if recursive==false', async function () {
104+
this.timeout(20 * 1000)
105+
// webworkers are not dialable because webrtc is not available
106+
const node = (await common.spawn({ type: isWebWorker ? 'go' : undefined })).api
107+
await ipfs.swarm.connect(node.peerId.addresses[0])
108+
const { path } = await ipfs.add(uint8ArrayFromString('should resolve an IPNS key if recursive === false'))
109+
const { id: keyId } = await ipfs.key.gen('new-key-name', { type: 'rsa', size: 2048 })
110+
111+
await ipfs.name.publish(path, { allowOffline: true })
112+
await ipfs.name.publish(`/ipns/${ipfs.peerId.id}`, { allowOffline: true, key: 'new-key-name', resolve: false })
113+
114+
return expect(await ipfs.resolve(`/ipns/${keyId}`, { recursive: false }))
115+
.to.eq(`/ipns/${ipfs.peerId.id}`)
116+
})
102117
})
103118
}

packages/ipfs-cli/src/commands/resolve.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
recursive: {
1515
alias: 'r',
1616
type: 'boolean',
17-
default: false
17+
default: true
1818
},
1919
'cid-base': {
2020
describe: 'Number base to display CIDs in.',

packages/ipfs-cli/test/resolve.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const cli = require('./utils/cli')
77
const sinon = require('sinon')
88

99
const defaultOptions = {
10-
recursive: false,
10+
recursive: true,
1111
cidBase: 'base58btc',
1212
timeout: undefined
1313
}
@@ -31,27 +31,24 @@ describe('resolve', () => {
3131
expect(out).to.equal(resolved + '\n')
3232
})
3333

34-
it('resolves a CID recursively', async () => {
34+
it('resolves a CID recursively by default', async () => {
3535
const resolved = `/ipfs/${cid}`
3636

37-
ipfs.resolve.withArgs(cid.toString(), {
38-
...defaultOptions,
39-
recursive: true
40-
}).resolves(resolved)
37+
ipfs.resolve.withArgs(cid.toString(), defaultOptions).resolves(resolved)
4138

4239
const out = await cli(`resolve ${cid} --recursive`, { ipfs })
4340
expect(out).to.equal(resolved + '\n')
4441
})
4542

46-
it('resolves a CID recursively (short option)', async () => {
43+
it('allows non-recursive lookups with flag', async () => {
4744
const resolved = `/ipfs/${cid}`
4845

4946
ipfs.resolve.withArgs(cid.toString(), {
5047
...defaultOptions,
51-
recursive: true
48+
recursive: false
5249
}).resolves(resolved)
5350

54-
const out = await cli(`resolve ${cid} -r`, { ipfs })
51+
const out = await cli(`resolve ${cid} --recursive=false`, { ipfs })
5552
expect(out).to.equal(resolved + '\n')
5653
})
5754

packages/ipfs-core/src/components/resolve.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ module.exports = ({ repo, codecs, bases, name }) => {
2727
}
2828
}
2929

30-
const [, , hash, ...rest] = path.split('/') // ['', 'ipfs', 'hash', ...path]
30+
const [, schema, hash, ...rest] = path.split('/') // ['', 'ipfs', 'hash', ...path]
3131
const cid = CID.parse(hash)
3232
const base = opts.cidBase ? await bases.getBase(opts.cidBase) : undefined
3333

3434
// nothing to resolve return the input
3535
if (rest.length === 0) {
36-
return `/ipfs/${cid.toString(base && base.encoder)}`
36+
return `/${schema}/${cid.toString(base && base.encoder)}`
3737
}
3838

3939
path = rest.join('/')

0 commit comments

Comments
 (0)