diff --git a/src/cli/commands/ls.js b/src/cli/commands/ls.js index cbac9a049c..303c399c46 100644 --- a/src/cli/commands/ls.js +++ b/src/cli/commands/ls.js @@ -48,19 +48,12 @@ module.exports = { const multihashWidth = Math.max.apply(null, links.map((file) => file.hash.length)) const sizeWidth = Math.max.apply(null, links.map((file) => String(file.size).length)) - let pathParts = key.split('/') - - if (key.startsWith('/ipfs/')) { - pathParts = pathParts.slice(2) - } - links.forEach(link => { const fileName = link.type === 'dir' ? `${link.name || ''}/` : link.name - const padding = link.depth - pathParts.length print( rightpad(link.hash, multihashWidth + 1) + rightpad(link.size || '-', sizeWidth + 1) + - ' '.repeat(padding) + fileName + ' '.repeat(link.depth - 1) + fileName ) }) })()) diff --git a/src/core/components/files-regular/ls-pull-stream.js b/src/core/components/files-regular/ls-pull-stream.js index e1ec58ce10..57e4dddaa7 100644 --- a/src/core/components/files-regular/ls-pull-stream.js +++ b/src/core/components/files-regular/ls-pull-stream.js @@ -38,19 +38,14 @@ module.exports = function (self) { if (recursive) { return d.resolve(pull( toPullStream.source(exporter.recursive(file.cid, self._ipld, options)), - filter(child => file.cid.toBaseEncodedString() !== child.cid.toBaseEncodedString()), + filter(child => file.cid.toString() !== child.cid.toString()), map(mapFile(options)) )) } return d.resolve(pull( toPullStream.source(file.content()), - map(mapFile(options)), - map((file) => { - file.depth-- - - return file - }) + map(mapFile(options)) )) } diff --git a/src/core/components/files-regular/utils.js b/src/core/components/files-regular/utils.js index bd5afc5fd2..3faec81d1d 100644 --- a/src/core/components/files-regular/utils.js +++ b/src/core/components/files-regular/utils.js @@ -117,7 +117,7 @@ const mapFile = (options) => { hash: cidToString(file.cid, { base: options.cidBase }), path: file.path, name: file.name, - depth: file.path.split('/').length, + depth: file.path.split('/').length - 1, size, type } diff --git a/test/cli/ls.js b/test/cli/ls.js index bd5870c6fa..0c1875fa34 100644 --- a/test/cli/ls.js +++ b/test/cli/ls.js @@ -98,4 +98,17 @@ describe('ls', () => runOnAndOff((thing) => { 'mAXASICiW5ai+KiU60glImEMMkiHaNSOAivpXspriIhJO8iHI 2 version\n' ) }) + + + it('prints added files', async function () { + this.timeout(20 * 1000) + const out = await ipfs('ls Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z') + expect(out).to.eql( + 'QmamKEPmEH9RUsqRQsfNf5evZQDQPYL9KXg1ADeT7mkHkT - blocks/\n' + + 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3928 config\n' + + 'QmUqyZtPmsRy1U5Mo8kz2BAMmk1hfJ7yW1KAFTMB2odsFv - datastore/\n' + + 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU - init-docs/\n' + + 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 2 version\n' + ) + }) })) diff --git a/test/fixtures/test-data/contains-ipfs-name/some/ipfs/nice/file b/test/fixtures/test-data/contains-ipfs-name/some/ipfs/nice/file new file mode 100644 index 0000000000..4c5477a837 --- /dev/null +++ b/test/fixtures/test-data/contains-ipfs-name/some/ipfs/nice/file @@ -0,0 +1 @@ +Hey!