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

Commit 8c97de1

Browse files
authored
fix: tag stdin with mtime and mode when piping to cli 'add' (#2832)
Converts the stdin stream to a file object and tags it with the mtime and mode. fixes #2763
1 parent 99181c2 commit 8c97de1

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

packages/ipfs/src/cli/commands/add.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,11 @@ module.exports = {
236236
mode: argv.mode,
237237
mtime
238238
})
239-
: getStdin() // Pipe directly to ipfs.add
239+
: {
240+
content: getStdin(),
241+
mode: argv.mode,
242+
mtime
243+
} // Pipe to ipfs.add tagging with mode and mtime
240244

241245
let finalCid
242246

packages/ipfs/test/cli/files-regular.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ describe('files', () => {
157157
it('add from pipe', async () => {
158158
const cid = new CID('QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')
159159

160-
ipfs.add.withArgs(matchIterable(), defaultAddArgs()).returns([{
160+
ipfs.add.withArgs(sinon.match({
161+
content: matchIterable()
162+
}), defaultAddArgs()).returns([{
161163
cid,
162164
path: 'readme'
163165
}])
@@ -173,6 +175,28 @@ describe('files', () => {
173175
expect(out).to.equal(`added ${cid} ${cid}\n`)
174176
})
175177

178+
it('add from pipe with mtime=100', async () => {
179+
const cid = new CID('QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')
180+
181+
ipfs.add.withArgs(sinon.match({
182+
content: matchIterable(),
183+
mtime: { secs: 100 }
184+
}), defaultAddArgs()).returns([{
185+
cid,
186+
path: 'readme'
187+
}])
188+
189+
const proc = cli('add --mtime=100', {
190+
ipfs,
191+
getStdin: function * () {
192+
yield Buffer.from('hello\n')
193+
}
194+
})
195+
196+
const out = await proc
197+
expect(out).to.equal(`added ${cid} ${cid}\n`)
198+
})
199+
176200
it('add --quiet', async () => {
177201
const cid = new CID('QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')
178202

0 commit comments

Comments
 (0)