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

Commit

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

fixes #2763
  • Loading branch information
kanej authored Mar 25, 2020
1 parent 99181c2 commit 8c97de1
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-regular.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 8c97de1

Please sign in to comment.