Skip to content

Commit

Permalink
fix: allow all supported unixfs time types (#111)
Browse files Browse the repository at this point in the history
Date is not fine grained enough - nanoseconds are ignored so expand
the supported types of time representation allowed.
  • Loading branch information
achingbrain authored Mar 22, 2021
1 parent 60b6a27 commit 72e0097
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"@types/fs-extra": "^9.0.5",
"aegir": "^30.3.0",
"delay": "^5.0.0",
"ipfs-unixfs": "^4.0.1",
"it-all": "^1.0.4",
"it-drain": "^1.0.3",
"it-last": "^1.0.4",
Expand Down
2 changes: 1 addition & 1 deletion src/files/glob-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const errCode = require('err-code')
* @param {boolean} [options.preserveMode] - preserve mode
* @param {boolean} [options.preserveMtime] - preserve mtime
* @param {number} [options.mode] - mode to use - if preserveMode is true this will be ignored
* @param {Date} [options.mtime] - mtime to use - if preserveMtime is true this will be ignored
* @param {import('ipfs-unixfs').MtimeLike} [options.mtime] - mtime to use - if preserveMtime is true this will be ignored
* @yields {Object} File objects in the form `{ path: String, content: AsyncIterator<Buffer> }`
*/
module.exports = async function * globSource (paths, options) {
Expand Down
36 changes: 36 additions & 0 deletions test/files/glob-source.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,40 @@ describe('glob-source', () => {
expect(result).to.have.nested.property('[5].path', '/dir/nested-dir/other.txt')
expect(result).to.have.deep.nested.property('[5].mtime', new Date(5))
})

it('overrides mtime for file with secs/nsecs', async function () {
if (!isNode) {
return this.skip()
}

const result = await all(globSource(fixture('/dir/file-1.txt'), {
mtime: { secs: 5, nsecs: 0 }
}))

expect(result).to.have.deep.nested.property('[0].mtime', { secs: 5, nsecs: 0 })
})

it('overrides mtime for file with hrtime', async function () {
if (!isNode) {
return this.skip()
}

const result = await all(globSource(fixture('/dir/file-1.txt'), {
mtime: [5, 0]
}))

expect(result).to.have.deep.nested.property('[0].mtime', [5, 0])
})

it('overrides mtime for file with UnixFS timespec', async function () {
if (!isNode) {
return this.skip()
}

const result = await all(globSource(fixture('/dir/file-1.txt'), {
mtime: { Seconds: 5, FractionalNanoseconds: 0 }
}))

expect(result).to.have.deep.nested.property('[0].mtime', { Seconds: 5, FractionalNanoseconds: 0 })
})
})

0 comments on commit 72e0097

Please sign in to comment.