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

fix: files.cat: detect and handle errors when unknown path and cat dir #1143

Merged
merged 1 commit into from
Dec 12, 2017
Merged
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
"progress": "^2.0.0",
"promisify-es6": "^1.0.3",
"pull-abortable": "^4.1.1",
"pull-defer": "^0.2.2",
"pull-file": "^1.1.0",
"pull-ndjson": "^0.1.1",
"pull-paramap": "^1.2.2",
Expand Down
22 changes: 13 additions & 9 deletions src/core/components/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,19 @@ module.exports = function files (self) {
pull.collect((err, files) => {
if (err) { d.end(err) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this missing a return?

if (!files || !files.length) {
return d.end(new Error('No such file'))
return d.abort(new Error('No such file'))
}

const content = files[files.length - 1].content
if (files.length > 1) {
files = files.filter((file) => file.path === ipfsPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here file.path is the path from the root e.g. tour and tour/0.0-intro, and ipfsPath is the full path e.g. /ipfs/QmfGBRT6BbWJd7yUc2uYdaUZJBbnEFvTqehPFoSMQ6wgdr/tour.

This filter is removing all the files from the array and so files[0] below is undefined

screen shot 2017-12-14 at 12 13 48

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alanshaw !
#1148 should fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theres's still an issue here, where "tour" dir is being filtered out prematurely because the output path doesn't match the input. Digging in...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... which should be fixed f6c15c6

}

const file = files[0]

const content = file.content
if (!content && file.type === 'dir') {
return d.abort(new Error('this dag node is a directory'))
}
d.resolve(content)
})
)
Expand Down Expand Up @@ -206,21 +215,16 @@ module.exports = function files (self) {
addPullStream: _addPullStream,

cat: promisify((ipfsPath, callback) => {
const p = _catPullStream(ipfsPath)
pull(
p,
_catPullStream(ipfsPath),
pull.collect((err, buffers) => {
if (err) { return callback(err) }
callback(null, Buffer.concat(buffers))
})
)
}),

catReadableStream: (ipfsPath) => {
const p = _catPullStream(ipfsPath)

return toStream.source(p)
},
catReadableStream: (ipfsPath) => toStream.source(_catPullStream(ipfsPath)),

catPullStream: _catPullStream,

Expand Down