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

Commit e156c47

Browse files
pgterichardschneider
authored andcommitted
fix: ipfs.ls: allow any depth (#1152)
* fix: ipfs ls: allow any depth. Should fix #1079 * chore: CLI: tests: added recursive ls test * fix bitswap timeouts
1 parent a86d0eb commit e156c47

File tree

3 files changed

+51
-32
lines changed

3 files changed

+51
-32
lines changed

src/core/components/files.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ module.exports = function files (self) {
161161
}
162162

163163
function _lsPullStreamImmutable (ipfsPath) {
164+
const path = normalizePath(ipfsPath)
165+
const depth = path.split('/').length
164166
return pull(
165-
exporter(ipfsPath, self._ipldResolver, { maxDepth: 1 }),
166-
pull.filter((node) => node.depth === 1),
167+
exporter(ipfsPath, self._ipldResolver, { maxDepth: depth }),
168+
pull.filter((node) => node.depth === depth),
167169
pull.map((node) => {
168170
node = Object.assign({}, node, { hash: toB58String(node.hash) })
169171
delete node.content

test/cli/bitswap.js

+30-30
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,39 @@
44
const expect = require('chai').expect
55
const runOn = require('../utils/on-and-off').on
66

7-
describe('bitswap', function () {
8-
runOn((thing) => {
9-
this.timeout(30000)
10-
let ipfs
11-
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'
7+
describe('bitswap', () => runOn((thing) => {
8+
let ipfs
9+
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'
1210

13-
before((done) => {
14-
ipfs = thing.ipfs
15-
ipfs('block get ' + key)
16-
.then(() => {})
17-
.catch(() => {})
18-
setTimeout(done, 800)
19-
})
11+
before((done) => {
12+
ipfs = thing.ipfs
13+
ipfs('block get ' + key)
14+
.then(() => {})
15+
.catch(() => {})
16+
setTimeout(done, 800)
17+
})
2018

21-
it('wantlist', () => {
22-
return ipfs('bitswap wantlist').then((out) => {
23-
expect(out).to.eql(key + '\n')
24-
})
19+
it('wantlist', function () {
20+
this.timeout(20 * 1000)
21+
return ipfs('bitswap wantlist').then((out) => {
22+
expect(out).to.eql(key + '\n')
2523
})
24+
})
25+
26+
it('stat', function () {
27+
this.timeout(20 * 1000)
2628

27-
it('stat', () => {
28-
return ipfs('bitswap stat').then((out) => {
29-
expect(out).to.be.eql([
30-
'bitswap status',
31-
' blocks received: 0',
32-
' dup blocks received: 0',
33-
' dup data received: 0B',
34-
' wantlist [1 keys]',
35-
` ${key}`,
36-
' partners [0]',
37-
' '
38-
].join('\n') + '\n')
39-
})
29+
return ipfs('bitswap stat').then((out) => {
30+
expect(out).to.be.eql([
31+
'bitswap status',
32+
' blocks received: 0',
33+
' dup blocks received: 0',
34+
' dup data received: 0B',
35+
' wantlist [1 keys]',
36+
` ${key}`,
37+
' partners [0]',
38+
' '
39+
].join('\n') + '\n')
4040
})
4141
})
42-
})
42+
}))

test/cli/files.js

+17
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,23 @@ describe('files', () => runOnAndOff((thing) => {
311311
})
312312
})
313313

314+
it('ls <subdir>', function () {
315+
this.timeout(20 * 1000)
316+
317+
return ipfs('ls /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs')
318+
.then((out) => {
319+
expect(out).to.eql(
320+
'QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1688 about\n' +
321+
'QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 200 contact\n' +
322+
'QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC 65 docs/\n' +
323+
'QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 322 help\n' +
324+
'QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1728 quick-start\n' +
325+
'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1102 readme\n' +
326+
'QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1027 security-notes\n' +
327+
'QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te 863 tour/\n')
328+
})
329+
})
330+
314331
it('ls --help', function () {
315332
this.timeout(20 * 1000)
316333

0 commit comments

Comments
 (0)