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

[WIP] fix: trailing slash in ls crash #2540

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/cli/commands/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
})
})())
Expand Down
9 changes: 2 additions & 7 deletions src/core/components/files-regular/ls-pull-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
))
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/components/files-regular/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 13 additions & 0 deletions test/cli/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
})
}))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hey!