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

Commit

Permalink
fix: ipfs.ls: allow any depth (#1152)
Browse files Browse the repository at this point in the history
* fix: ipfs ls: allow any depth. Should fix #1079

* chore: CLI: tests: added recursive ls test

* fix bitswap timeouts
  • Loading branch information
pgte authored and daviddias committed Dec 17, 2017
1 parent 962050e commit 279af78
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 32 deletions.
6 changes: 4 additions & 2 deletions src/core/components/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ module.exports = function files (self) {
}

function _lsPullStreamImmutable (ipfsPath) {
const path = normalizePath(ipfsPath)
const depth = path.split('/').length
return pull(
exporter(ipfsPath, self._ipldResolver, { maxDepth: 1 }),
pull.filter((node) => node.depth === 1),
exporter(ipfsPath, self._ipldResolver, { maxDepth: depth }),
pull.filter((node) => node.depth === depth),
pull.map((node) => {
node = Object.assign({}, node, { hash: toB58String(node.hash) })
delete node.content
Expand Down
60 changes: 30 additions & 30 deletions test/cli/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@
const expect = require('chai').expect
const runOn = require('../utils/on-and-off').on

describe('bitswap', function () {
runOn((thing) => {
this.timeout(30000)
let ipfs
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'
describe('bitswap', () => runOn((thing) => {
let ipfs
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'

before((done) => {
ipfs = thing.ipfs
ipfs('block get ' + key)
.then(() => {})
.catch(() => {})
setTimeout(done, 800)
})
before((done) => {
ipfs = thing.ipfs
ipfs('block get ' + key)
.then(() => {})
.catch(() => {})
setTimeout(done, 800)
})

it('wantlist', () => {
return ipfs('bitswap wantlist').then((out) => {
expect(out).to.eql(key + '\n')
})
it('wantlist', function () {
this.timeout(20 * 1000)
return ipfs('bitswap wantlist').then((out) => {
expect(out).to.eql(key + '\n')
})
})

it('stat', function () {
this.timeout(20 * 1000)

it('stat', () => {
return ipfs('bitswap stat').then((out) => {
expect(out).to.be.eql([
'bitswap status',
' blocks received: 0',
' dup blocks received: 0',
' dup data received: 0B',
' wantlist [1 keys]',
` ${key}`,
' partners [0]',
' '
].join('\n') + '\n')
})
return ipfs('bitswap stat').then((out) => {
expect(out).to.be.eql([
'bitswap status',
' blocks received: 0',
' dup blocks received: 0',
' dup data received: 0B',
' wantlist [1 keys]',
` ${key}`,
' partners [0]',
' '
].join('\n') + '\n')
})
})
})
}))
17 changes: 17 additions & 0 deletions test/cli/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,23 @@ describe('files', () => runOnAndOff((thing) => {
})
})

it('ls <subdir>', function () {
this.timeout(20 * 1000)

return ipfs('ls /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs')
.then((out) => {
expect(out).to.eql(
'QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1688 about\n' +
'QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 200 contact\n' +
'QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC 65 docs/\n' +
'QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 322 help\n' +
'QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1728 quick-start\n' +
'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1102 readme\n' +
'QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1027 security-notes\n' +
'QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te 863 tour/\n')
})
})

it('ls --help', function () {
this.timeout(20 * 1000)

Expand Down

0 comments on commit 279af78

Please sign in to comment.