Skip to content

Commit 72e0097

Browse files
authored
fix: allow all supported unixfs time types (#111)
Date is not fine grained enough - nanoseconds are ignored so expand the supported types of time representation allowed.
1 parent 60b6a27 commit 72e0097

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"@types/fs-extra": "^9.0.5",
6666
"aegir": "^30.3.0",
6767
"delay": "^5.0.0",
68+
"ipfs-unixfs": "^4.0.1",
6869
"it-all": "^1.0.4",
6970
"it-drain": "^1.0.3",
7071
"it-last": "^1.0.4",

src/files/glob-source.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const errCode = require('err-code')
1717
* @param {boolean} [options.preserveMode] - preserve mode
1818
* @param {boolean} [options.preserveMtime] - preserve mtime
1919
* @param {number} [options.mode] - mode to use - if preserveMode is true this will be ignored
20-
* @param {Date} [options.mtime] - mtime to use - if preserveMtime is true this will be ignored
20+
* @param {import('ipfs-unixfs').MtimeLike} [options.mtime] - mtime to use - if preserveMtime is true this will be ignored
2121
* @yields {Object} File objects in the form `{ path: String, content: AsyncIterator<Buffer> }`
2222
*/
2323
module.exports = async function * globSource (paths, options) {

test/files/glob-source.spec.js

+36
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,40 @@ describe('glob-source', () => {
233233
expect(result).to.have.nested.property('[5].path', '/dir/nested-dir/other.txt')
234234
expect(result).to.have.deep.nested.property('[5].mtime', new Date(5))
235235
})
236+
237+
it('overrides mtime for file with secs/nsecs', async function () {
238+
if (!isNode) {
239+
return this.skip()
240+
}
241+
242+
const result = await all(globSource(fixture('/dir/file-1.txt'), {
243+
mtime: { secs: 5, nsecs: 0 }
244+
}))
245+
246+
expect(result).to.have.deep.nested.property('[0].mtime', { secs: 5, nsecs: 0 })
247+
})
248+
249+
it('overrides mtime for file with hrtime', async function () {
250+
if (!isNode) {
251+
return this.skip()
252+
}
253+
254+
const result = await all(globSource(fixture('/dir/file-1.txt'), {
255+
mtime: [5, 0]
256+
}))
257+
258+
expect(result).to.have.deep.nested.property('[0].mtime', [5, 0])
259+
})
260+
261+
it('overrides mtime for file with UnixFS timespec', async function () {
262+
if (!isNode) {
263+
return this.skip()
264+
}
265+
266+
const result = await all(globSource(fixture('/dir/file-1.txt'), {
267+
mtime: { Seconds: 5, FractionalNanoseconds: 0 }
268+
}))
269+
270+
expect(result).to.have.deep.nested.property('[0].mtime', { Seconds: 5, FractionalNanoseconds: 0 })
271+
})
236272
})

0 commit comments

Comments
 (0)