From 65a040dadd68ca5cb6697c8fd15922f505833a19 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 4 Jun 2020 11:43:50 +0100 Subject: [PATCH 1/3] fix: ignore high mode bits passed to constructor The UnixFS Spec says high mode bits not defined in the version of the spec supported by a given implementation should be ignored but also persisted to ensure forwards compatibility. The change here: 1. Ignores high bits passed to the constructor 1. Respects high bits read out of a protobuf though does not expose them 1. Writes high bits back to a protobuf but only if they were read from a protobuf to begin with --- packages/ipfs-unixfs-exporter/package.json | 2 +- packages/ipfs-unixfs-importer/package.json | 2 +- packages/ipfs-unixfs/package.json | 2 +- packages/ipfs-unixfs/src/index.js | 8 ++- .../ipfs-unixfs/test/unixfs-format.spec.js | 61 +++++++++++++++++++ 5 files changed, 70 insertions(+), 5 deletions(-) diff --git a/packages/ipfs-unixfs-exporter/package.json b/packages/ipfs-unixfs-exporter/package.json index 7b79785b..e9ef3b1c 100644 --- a/packages/ipfs-unixfs-exporter/package.json +++ b/packages/ipfs-unixfs-exporter/package.json @@ -36,7 +36,7 @@ "homepage": "https://github.com/ipfs/js-ipfs-unixfs#readme", "devDependencies": { "abort-controller": "^3.0.0", - "aegir": "^21.9.0", + "aegir": "^22.0.0", "chai": "^4.2.0", "chai-as-promised": "^7.1.1", "detect-node": "^2.0.4", diff --git a/packages/ipfs-unixfs-importer/package.json b/packages/ipfs-unixfs-importer/package.json index bbf56d6d..c320eaeb 100644 --- a/packages/ipfs-unixfs-importer/package.json +++ b/packages/ipfs-unixfs-importer/package.json @@ -35,7 +35,7 @@ }, "homepage": "https://github.com/ipfs/js-ipfs-unixfs#readme", "devDependencies": { - "aegir": "^21.9.0", + "aegir": "^22.0.0", "chai": "^4.2.0", "cids": "^0.8.0", "detect-node": "^2.0.4", diff --git a/packages/ipfs-unixfs/package.json b/packages/ipfs-unixfs/package.json index 2e04dac3..e8cd2f1a 100644 --- a/packages/ipfs-unixfs/package.json +++ b/packages/ipfs-unixfs/package.json @@ -35,7 +35,7 @@ }, "homepage": "https://github.com/ipfs/js-ipfs-unixfs#readme", "devDependencies": { - "aegir": "^21.9.0", + "aegir": "^22.0.0", "chai": "^4.2.0", "dirty-chai": "^2.0.1", "nyc": "^15.0.0" diff --git a/packages/ipfs-unixfs/src/index.js b/packages/ipfs-unixfs/src/index.js index 5f77a9c1..ae22d0b8 100644 --- a/packages/ipfs-unixfs/src/index.js +++ b/packages/ipfs-unixfs/src/index.js @@ -129,13 +129,18 @@ class Data { static unmarshal (marshaled) { const decoded = unixfsData.decode(marshaled) - return new Data({ + const data = new Data({ type: types[decoded.Type], data: decoded.hasData() ? decoded.Data : undefined, blockSizes: decoded.blocksizes, mode: decoded.hasMode() ? decoded.mode : undefined, mtime: decoded.hasMtime() ? decoded.mtime : undefined }) + + // make sure we honor the original mode + data._originalMode = decoded.hasMode() ? decoded.mode : undefined + + return data } constructor (...args) { @@ -158,7 +163,6 @@ class Data { this.hashType = hashType this.fanout = fanout this.blockSizes = blockSizes || [] - this._originalMode = mode const parsedMode = parseMode(mode) diff --git a/packages/ipfs-unixfs/test/unixfs-format.spec.js b/packages/ipfs-unixfs/test/unixfs-format.spec.js index e8bf137d..76cbe50f 100644 --- a/packages/ipfs-unixfs/test/unixfs-format.spec.js +++ b/packages/ipfs-unixfs/test/unixfs-format.spec.js @@ -331,6 +331,67 @@ describe('unixfs-format', () => { expect(entry).to.have.property('mode', mode) }) + it('omits default file mode from protobuf', () => { + const entry = new UnixFS({ + type: 'file', + mode: 0o644 + }) + + const marshaled = entry.marshal() + + const protobuf = unixfsData.decode(marshaled) + expect(protobuf.hasMode()).to.be.false() + }) + + it('omits default directory mode from protobuf', () => { + const entry = new UnixFS({ + type: 'directory', + mode: 0o755 + }) + + const marshaled = entry.marshal() + + const protobuf = unixfsData.decode(marshaled) + expect(protobuf.hasMode()).to.be.false() + }) + + it('respects high bits in mode read from buffer', () => { + const mode = 0o0100644 // similar to output from fs.stat + const buf = unixfsData.encode({ + Type: unixfsData.DataType.File, + mode + }) + + const entry = UnixFS.unmarshal(buf) + + // should have truncated mode to bits in the version of the spec this module supports + expect(entry).to.have.property('mode', 0o644) + + const marshaled = entry.marshal() + + const protobuf = unixfsData.decode(marshaled) + expect(protobuf).to.have.property('mode', mode) + }) + + it('ignores high bits in mode passed to constructor', () => { + const mode = 0o0100644 // similar to output from fs.stat + const entry = new UnixFS({ + type: 'file', + mode + }) + + // should have truncated mode to bits in the version of the spec this module supports + expect(entry).to.have.property('mode', 0o644) + + const marshaled = entry.marshal() + const unmarshaled = UnixFS.unmarshal(marshaled) + + expect(unmarshaled).to.have.property('mode', 0o644) + + const protobuf = unixfsData.decode(marshaled) + expect(protobuf.hasMode()).to.be.false() + }) + // figuring out what is this metadata for https://github.com/ipfs/js-ipfs-data-importing/issues/3#issuecomment-182336526 it('metadata', () => { const entry = new UnixFS({ From 08296868aab72bbf865d0271f62b5a7b814883d2 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 4 Jun 2020 13:31:14 +0100 Subject: [PATCH 2/3] chore: update contributors --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index df9a1109..da674924 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "Marcin Rataj ", "Richard Littauer ", "Mithgol ", + "Hector Sanjuan ", "Francisco Baio Dias ", "Diogo Silva ", "jbenet ", From 0b11fa2bf92062421c9a70025d0763e4a602ea79 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 4 Jun 2020 13:33:37 +0100 Subject: [PATCH 3/3] chore: publish - ipfs-unixfs-exporter@2.0.2 - ipfs-unixfs-importer@2.0.2 - ipfs-unixfs@1.0.3 --- packages/ipfs-unixfs-exporter/CHANGELOG.md | 11 +++++++++++ packages/ipfs-unixfs-exporter/package-lock.json | 2 +- packages/ipfs-unixfs-exporter/package.json | 6 +++--- packages/ipfs-unixfs-importer/CHANGELOG.md | 11 +++++++++++ packages/ipfs-unixfs-importer/package.json | 6 +++--- packages/ipfs-unixfs/CHANGELOG.md | 11 +++++++++++ packages/ipfs-unixfs/package.json | 2 +- 7 files changed, 41 insertions(+), 8 deletions(-) diff --git a/packages/ipfs-unixfs-exporter/CHANGELOG.md b/packages/ipfs-unixfs-exporter/CHANGELOG.md index 4f1188b9..3ef80809 100644 --- a/packages/ipfs-unixfs-exporter/CHANGELOG.md +++ b/packages/ipfs-unixfs-exporter/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.0.2](https://github.com/ipfs/js-ipfs-unixfs/compare/ipfs-unixfs-exporter@2.0.1...ipfs-unixfs-exporter@2.0.2) (2020-06-04) + + +### Bug Fixes + +* ignore high mode bits passed to constructor ([65a040d](https://github.com/ipfs/js-ipfs-unixfs/commit/65a040dadd68ca5cb6697c8fd15922f505833a19)) + + + + + ## [2.0.1](https://github.com/ipfs/js-ipfs-unixfs/compare/ipfs-unixfs-exporter@2.0.0...ipfs-unixfs-exporter@2.0.1) (2020-04-24) diff --git a/packages/ipfs-unixfs-exporter/package-lock.json b/packages/ipfs-unixfs-exporter/package-lock.json index 179a1932..8a963d95 100644 --- a/packages/ipfs-unixfs-exporter/package-lock.json +++ b/packages/ipfs-unixfs-exporter/package-lock.json @@ -1,6 +1,6 @@ { "name": "ipfs-unixfs-exporter", - "version": "2.0.1", + "version": "2.0.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/ipfs-unixfs-exporter/package.json b/packages/ipfs-unixfs-exporter/package.json index e9ef3b1c..3399fadc 100644 --- a/packages/ipfs-unixfs-exporter/package.json +++ b/packages/ipfs-unixfs-exporter/package.json @@ -1,6 +1,6 @@ { "name": "ipfs-unixfs-exporter", - "version": "2.0.1", + "version": "2.0.2", "description": "JavaScript implementation of the UnixFs exporter used by IPFS", "leadMaintainer": "Alex Potsides ", "main": "src/index.js", @@ -41,7 +41,7 @@ "chai-as-promised": "^7.1.1", "detect-node": "^2.0.4", "dirty-chai": "^2.0.1", - "ipfs-unixfs-importer": "^2.0.1", + "ipfs-unixfs-importer": "^2.0.2", "ipld": "^0.26.1", "ipld-dag-pb": "^0.18.5", "ipld-in-memory": "^4.0.0", @@ -57,7 +57,7 @@ "cids": "^0.8.0", "err-code": "^2.0.0", "hamt-sharding": "^1.0.0", - "ipfs-unixfs": "^1.0.2", + "ipfs-unixfs": "^1.0.3", "it-last": "^1.0.1", "multihashing-async": "^0.8.0" } diff --git a/packages/ipfs-unixfs-importer/CHANGELOG.md b/packages/ipfs-unixfs-importer/CHANGELOG.md index 24886e67..f9faa8ad 100644 --- a/packages/ipfs-unixfs-importer/CHANGELOG.md +++ b/packages/ipfs-unixfs-importer/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.0.2](https://github.com/ipfs/js-ipfs-unixfs/compare/ipfs-unixfs-importer@2.0.1...ipfs-unixfs-importer@2.0.2) (2020-06-04) + + +### Bug Fixes + +* ignore high mode bits passed to constructor ([65a040d](https://github.com/ipfs/js-ipfs-unixfs/commit/65a040dadd68ca5cb6697c8fd15922f505833a19)) + + + + + ## [2.0.1](https://github.com/ipfs/js-ipfs-unixfs/compare/ipfs-unixfs-importer@2.0.0...ipfs-unixfs-importer@2.0.1) (2020-04-24) diff --git a/packages/ipfs-unixfs-importer/package.json b/packages/ipfs-unixfs-importer/package.json index c320eaeb..0716ef81 100644 --- a/packages/ipfs-unixfs-importer/package.json +++ b/packages/ipfs-unixfs-importer/package.json @@ -1,6 +1,6 @@ { "name": "ipfs-unixfs-importer", - "version": "2.0.1", + "version": "2.0.2", "description": "JavaScript implementation of the UnixFs importer used by IPFS", "leadMaintainer": "Alex Potsides ", "main": "src/index.js", @@ -40,7 +40,7 @@ "cids": "^0.8.0", "detect-node": "^2.0.4", "dirty-chai": "^2.0.1", - "ipfs-unixfs-exporter": "^2.0.1", + "ipfs-unixfs-exporter": "^2.0.2", "ipld": "^0.26.1", "ipld-in-memory": "^4.0.0", "it-buffer-stream": "^1.0.2", @@ -55,7 +55,7 @@ "buffer": "^5.6.0", "err-code": "^2.0.0", "hamt-sharding": "^1.0.0", - "ipfs-unixfs": "^1.0.2", + "ipfs-unixfs": "^1.0.3", "ipld-dag-pb": "^0.18.5", "it-all": "^1.0.1", "it-batch": "^1.0.3", diff --git a/packages/ipfs-unixfs/CHANGELOG.md b/packages/ipfs-unixfs/CHANGELOG.md index 35605e9b..34bf9d40 100644 --- a/packages/ipfs-unixfs/CHANGELOG.md +++ b/packages/ipfs-unixfs/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.0.3](https://github.com/ipfs/js-ipfs-unixfs/compare/ipfs-unixfs@1.0.2...ipfs-unixfs@1.0.3) (2020-06-04) + + +### Bug Fixes + +* ignore high mode bits passed to constructor ([65a040d](https://github.com/ipfs/js-ipfs-unixfs/commit/65a040dadd68ca5cb6697c8fd15922f505833a19)) + + + + + ## [1.0.2](https://github.com/ipfs/js-ipfs-unixfs/compare/ipfs-unixfs@1.0.1...ipfs-unixfs@1.0.2) (2020-04-24) diff --git a/packages/ipfs-unixfs/package.json b/packages/ipfs-unixfs/package.json index e8cd2f1a..d5d2f5b4 100644 --- a/packages/ipfs-unixfs/package.json +++ b/packages/ipfs-unixfs/package.json @@ -1,6 +1,6 @@ { "name": "ipfs-unixfs", - "version": "1.0.2", + "version": "1.0.3", "description": "JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a MerkleDAG)", "leadMaintainer": "Alex Potsides ", "main": "src/index.js",