-
Notifications
You must be signed in to change notification settings - Fork 37
fix: allow mtime and mode to be optional #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
00e5ea0
3a86a0b
04ea7a1
397931e
1ee93a1
a6c4208
e232acf
9517501
45b0b30
d93b32b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,37 +79,33 @@ describe('unixfs-format', () => { | |
expect(data.blockSizes).to.not.deep.equal(unmarshalled.blockSizes) | ||
}) | ||
|
||
it('default mode for files', () => { | ||
it('mode', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any way I can convince you to make the spec follow golang's Having already paid for transporting a 32bit value, it seems so odd to not populate the rest of the bits if we have them. In js-ipfs you can of course simply mask them off, the point is for the spec to allow it... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there anything in the spec that prevents us filling the higher bits with subsequent PRs? From my understanding all we've done so far is specify the equivalent of the file mode component of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @achingbrain yes you are correct. I crossed wires with not explicitly masking off future bits for when we do add them, I left a comment to the effect above |
||
const mode = parseInt('0555', 8) | ||
const data = new UnixFS('file') | ||
expect(data.mode).to.equal(parseInt('0644', 8)) | ||
const marshalled = data.marshal() | ||
const unmarshalled = UnixFS.unmarshal(marshalled) | ||
expect(unmarshalled.mode).to.equal(parseInt('0644', 8)) | ||
}) | ||
data.mode = mode | ||
|
||
it('default mode for directories', () => { | ||
const data = new UnixFS('directory') | ||
expect(data.mode).to.equal(parseInt('0755', 8)) | ||
const marshalled = data.marshal() | ||
const unmarshalled = UnixFS.unmarshal(marshalled) | ||
expect(unmarshalled.mode).to.equal(parseInt('0755', 8)) | ||
expect(UnixFS.unmarshal(data.marshal())).to.have.property('mode', mode) | ||
}) | ||
|
||
it('default mode for hamt-sharded-directories', () => { | ||
const data = new UnixFS('hamt-sharded-directory') | ||
expect(data.mode).to.equal(parseInt('0755', 8)) | ||
const marshalled = data.marshal() | ||
const unmarshalled = UnixFS.unmarshal(marshalled) | ||
expect(unmarshalled.mode).to.equal(parseInt('0755', 8)) | ||
it('removes mode', () => { | ||
const mode = parseInt('0555', 8) | ||
const data = new UnixFS('file') | ||
data.mode = mode | ||
|
||
const unmarshalled = UnixFS.unmarshal(data.marshal()) | ||
expect(unmarshalled).to.have.property('mode', mode) | ||
|
||
delete unmarshalled.mode | ||
|
||
expect(UnixFS.unmarshal(unmarshalled.marshal())).to.not.have.property('mode') | ||
}) | ||
|
||
it('mode', () => { | ||
const mode = parseInt('0555', 8) | ||
it('sets mode to 0', () => { | ||
const mode = 0 | ||
const data = new UnixFS('file') | ||
data.mode = mode | ||
const marshalled = data.marshal() | ||
const unmarshalled = UnixFS.unmarshal(marshalled) | ||
expect(unmarshalled.mode).to.equal(mode) | ||
|
||
expect(UnixFS.unmarshal(data.marshal())).to.have.property('mode', mode) | ||
}) | ||
|
||
it('mtime', () => { | ||
|
@@ -121,6 +117,27 @@ describe('unixfs-format', () => { | |
expect(unmarshalled.mtime).to.equal(mtime) | ||
}) | ||
|
||
it('removes mtime', () => { | ||
const mtime = parseInt(Date.now() / 1000) | ||
const data = new UnixFS('file') | ||
data.mtime = mtime | ||
|
||
const unmarshalled = UnixFS.unmarshal(data.marshal()) | ||
expect(unmarshalled).to.have.property('mtime', mtime) | ||
|
||
delete unmarshalled.mtime | ||
|
||
expect(UnixFS.unmarshal(unmarshalled.marshal())).to.not.have.property('mtime') | ||
}) | ||
|
||
it('sets mtime to 0', () => { | ||
const mtime = 0 | ||
const data = new UnixFS('file') | ||
data.mtime = mtime | ||
|
||
expect(UnixFS.unmarshal(data.marshal())).to.have.property('mtime', mtime) | ||
}) | ||
|
||
// figuring out what is this metadata for https://github.com/ipfs/js-ipfs-data-importing/issues/3#issuecomment-182336526 | ||
it.skip('metadata', () => {}) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per ipfs/specs#231, this needs to mask off with
07777
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not in the spec yet, will do a further PR if it gets added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, let's be careful. If we get a file that has extra bits, we should round-trip those bits. Otherwise, it's hard to add features later.