Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 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
19 changes: 15 additions & 4 deletions src/cli/commands/files/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const paramap = require('pull-paramap')
const zip = require('pull-zip')
const toPull = require('stream-to-pull-stream')

const WRAPPER = 'wrapper/'

function checkPath (inPath, recursive) {
// This function is to check for the following possible inputs
// 1) "." add the cwd but throw error for no recursion flag
Expand Down Expand Up @@ -53,6 +55,11 @@ module.exports = {
type: 'boolean',
default: false,
describe: 'Use the trickle DAG builder'
},
'wrap-with-directory': {
alias: 'w',
type: 'boolean',
default: false
}
},

Expand Down Expand Up @@ -94,14 +101,14 @@ module.exports = {
list = [inPath]
}

addPipeline(index, addStream, list)
addPipeline(index, addStream, list, argv.wrapWithDirectory)
})
})
})
}
}

function addPipeline (index, addStream, list) {
function addPipeline (index, addStream, list, wrapWithDirectory) {
pull(
zip(
pull.values(list),
Expand All @@ -117,12 +124,16 @@ function addPipeline (index, addStream, list) {
pull.filter((file) => !file.isDirectory),
pull.map((file) => ({
path: file.path.substring(index, file.path.length),
content: fs.createReadStream(file.path)
originalPath: file.path
})),
pull.map((file) => ({
path: wrapWithDirectory ? `${WRAPPER}${file.path}` : file.path,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this should use path.join to ensure correct path separators

content: fs.createReadStream(file.originalPath)
})),
addStream,
pull.map((file) => ({
hash: file.hash,
path: file.path
path: wrapWithDirectory ? file.path.substring(WRAPPER.length) : file.path
})),
pull.collect((err, added) => {
if (err) {
Expand Down
9 changes: 9 additions & 0 deletions test/cli/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ describe('files', () => runOnAndOff((thing) => {
})
})

it('add and wrap with a directory', () => {
return ipfs('add -w src/init-files/init-docs/readme').then((out) => {
expect(out).to.be.eql([
'added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme',
'added QmapdaVPjHXdcswef82FnGQUauMNpk9xYFkLDZKgAxhMwq'
].join('\n'))
})
})

it('cat', () => {
return ipfs('files cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')
.then((out) => {
Expand Down