Skip to content
This repository was archived by the owner on Apr 29, 2020. It is now read-only.
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
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = (path, dag, options) => {
pull.values([{
multihash: cid.buffer,
name: dPath.base,
path: dPath.base,
path: `${dPath.base}${dPath.rest.length ? `/${dPath.rest.join('/')}` : ''}`,
pathRest: dPath.rest,
depth: 0
}]),
Expand Down
29 changes: 25 additions & 4 deletions src/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,23 @@ function createResolver (dag, options, depth, parent) {

const cid = new CID(item.multihash)

waterfall([
(done) => dag.get(cid, done),
(node, done) => done(null, resolveItem(cid, node.value, item, options))
], cb)
dag.get(cid, item.pathRest.join('/'), (err, result) => {
if (err) {
if (err.message.includes('path not available')) {
return cb()
}

return cb(err)
}

const remainder = toPathComponents(result.remainderPath)

item.name = toPathComponents(item.path).pop()
item.pathRest = remainder
item.multihash = result.cid.buffer

cb(null, resolveItem(result.cid, result.value, item, options))
})
}),
pull.flatten(),
pull.filter(Boolean),
Expand Down Expand Up @@ -99,3 +112,11 @@ function typeOf (node) {
function identity (o) {
return o
}

const toPathComponents = (path = '') => {
// split on / unless escaped with \
return (path
.trim()
.match(/([^\\\][^/]|\\\/)+/g) || [])
.filter(Boolean)
}
19 changes: 13 additions & 6 deletions test/exporter-subtree.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,24 @@ describe('exporter subtree', () => {
importer(ipld),
pull.collect(cb)
),
(files, cb) => cb(null, files.pop().multihash),
(buf, cb) => cb(null, new CID(buf)),
(cid, cb) => pull(
exporter(`${cid.toBaseEncodedString()}/level-1/200Bytes.txt`, ipld),
pull.collect((err, files) => cb(err, { cid, files }))
(files, cb) => cb(null, [
files[1].multihash,
files[3].multihash
]),
([ targetFileCidBuf, containingFolderCidBuf ], cb) => cb(null, [
new CID(targetFileCidBuf),
new CID(containingFolderCidBuf)
]),
([ targetFileCid, containingFolderCid ], cb) => pull(
exporter(`${containingFolderCid.toBaseEncodedString()}/level-1/200Bytes.txt`, ipld),
pull.collect((err, files) => cb(err, { targetFileCid, containingFolderCid, files }))
),
({ cid, files }, cb) => {
({ targetFileCid, containingFolderCid, files }, cb) => {
files.forEach(file => expect(file).to.have.property('hash'))

expect(files.length).to.equal(1)
expect(files[0].path).to.equal('200Bytes.txt')
expect(files[0].hash).to.deep.equal(targetFileCid.buffer)
fileEql(files[0], content, cb)
}
], done)
Expand Down
2 changes: 1 addition & 1 deletion test/exporter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ describe('exporter', () => {
})
})

it('small file in a directory with an escaped slash in the title', (done) => {
it.only('small file in a directory with an escaped slash in the title', (done) => {
const fileName = `small-\\/file-${Math.random()}.txt`
const filePath = `/foo/${fileName}`

Expand Down