Skip to content

Commit

Permalink
fix: tag stdin with mtime and mode when piping to cli 'add'
Browse files Browse the repository at this point in the history
Converts the stdin stream to file object and tags that file with the mtime and mode.

fixes ipfs#2763
  • Loading branch information
kanej committed Mar 24, 2020
1 parent bfba767 commit 4a5c571
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/ipfs/src/cli/commands/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ module.exports = {
mode: argv.mode,
mtime
})
: getStdin() // Pipe directly to ipfs.add
: {
content: getStdin(),
mode: argv.mode,
mtime
} // Pipe to ipfs.add tagging with mode and mtime

let finalCid

Expand Down
26 changes: 25 additions & 1 deletion packages/ipfs/test/cli/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ describe('files', () => {
it('add from pipe', async () => {
const cid = new CID('QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')

ipfs.add.withArgs(matchIterable(), defaultAddArgs()).returns([{
ipfs.add.withArgs(sinon.match({
content: matchIterable()
}), defaultAddArgs()).returns([{
cid,
path: 'readme'
}])
Expand All @@ -173,6 +175,28 @@ describe('files', () => {
expect(out).to.equal(`added ${cid} ${cid}\n`)
})

it('add from pipe with mtime=100', async () => {
const cid = new CID('QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')

ipfs.add.withArgs(sinon.match({
content: matchIterable(),
mtime: { secs: 100 }
}), defaultAddArgs()).returns([{
cid,
path: 'readme'
}])

const proc = cli('add --mtime=100', {
ipfs,
getStdin: function * () {
yield Buffer.from('hello\n')
}
})

const out = await proc
expect(out).to.equal(`added ${cid} ${cid}\n`)
})

it('add --quiet', async () => {
const cid = new CID('QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')

Expand Down

0 comments on commit 4a5c571

Please sign in to comment.