From 271d44d5e22ffc59d147c456f7bdcee41ba64a61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Wed, 28 Feb 2018 20:00:14 +0100 Subject: [PATCH 1/2] complete files.stat with the 'with-local' option --- SPEC/FILES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SPEC/FILES.md b/SPEC/FILES.md index 3345fc34..42156fe7 100644 --- a/SPEC/FILES.md +++ b/SPEC/FILES.md @@ -618,6 +618,7 @@ Where: - `options` is an optional Object that might contain the following keys: - `hash` is a Boolean value to return only the hash. - `size` is a Boolean value to return only the size. + - `withLocal` is a Boolean value to compute the amount of the dag that is local, and if possible the total size. `callback` must follow the `function (err, stat) {}` signature, where `err` is an Error if the operation was not successful and `stat` is an Object with the following keys: @@ -626,6 +627,10 @@ Where: - `cumulativeSize` is an integer with the cumulative size in Bytes. - `blocks` is an integer indicating the number of blocks. - `type` is a string that can be either `directory` or `file`. +- `withLocality` is a boolean to indicate if locality information are present. +- `local` is a boolean to indicate if the queried dag is fully present locally. +- `sizeLocal` is an integer indicating the cumulative size of the data present locally. + If no `callback` is passed, a promise is returned. From 761fcee1448aa297841f093e4742ba0e733dc807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Tue, 6 Mar 2018 18:43:34 +0100 Subject: [PATCH 2/2] add tests for ipfs files stat --with-local --- js/src/files-mfs.js | 54 +++++++++++++++++++++++++++++++++++++++++++-- js/src/files.js | 33 ++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/js/src/files-mfs.js b/js/src/files-mfs.js index f51a7f9d..a34aa4d4 100644 --- a/js/src/files-mfs.js +++ b/js/src/files-mfs.js @@ -276,7 +276,10 @@ module.exports = (common) => { blocks: 1, size: 13, hash: 'QmcZojhwragQr5qhTeFAmELik623Z21e3jBTpJXoQ9si1T', - cumulativeSize: 71 + cumulativeSize: 71, + withLocality: false, + local: undefined, + sizeLocal: undefined }) done() }) @@ -295,7 +298,54 @@ module.exports = (common) => { blocks: 2, size: 0, hash: 'QmVrkkNurBCeJvPRohW5JTvJG4AxGrFg7FnmsZZUS6nJto', - cumulativeSize: 216 + cumulativeSize: 216, + withLocality: false, + local: undefined, + sizeLocal: undefined + }) + done() + }) + }) + + it('stat withLocal file', function (done) { + if (!withGo) { + console.log('Not supported in js-ipfs yet') + this.skip() + } + + ipfs.files.stat('/test/b', {'withLocal': true}, (err, stat) => { + expect(err).to.not.exist() + expect(stat).to.eql({ + type: 'file', + blocks: 1, + size: 13, + hash: 'QmcZojhwragQr5qhTeFAmELik623Z21e3jBTpJXoQ9si1T', + cumulativeSize: 71, + withLocality: true, + local: true, + sizeLocal: 71 + }) + done() + }) + }) + + it('stat withLocal dir', function (done) { + if (!withGo) { + console.log('Not supported in js-ipfs yet') + this.skip() + } + + ipfs.files.stat('/test', {'withLocal': true}, (err, stat) => { + expect(err).to.not.exist() + expect(stat).to.eql({ + type: 'directory', + blocks: 2, + size: 0, + hash: 'QmVrkkNurBCeJvPRohW5JTvJG4AxGrFg7FnmsZZUS6nJto', + cumulativeSize: 216, + withLocality: true, + local: true, + sizeLocal: 216 }) done() }) diff --git a/js/src/files.js b/js/src/files.js index 6205c4e0..fdd40060 100644 --- a/js/src/files.js +++ b/js/src/files.js @@ -24,6 +24,7 @@ module.exports = (common) => { this.timeout(40 * 1000) let ipfs + let withGo function fixture (path) { return loadFixture(path, 'interface-ipfs-core') @@ -60,7 +61,11 @@ module.exports = (common) => { factory.spawnNode((err, node) => { expect(err).to.not.exist() ipfs = node - done() + node.id((err, id) => { + expect(err).to.not.exist() + withGo = id.agentVersion.startsWith('go-ipfs') + done() + }) }) }) }) @@ -980,5 +985,31 @@ module.exports = (common) => { ) }) }) + + describe('.stat', () => { + before((done) => ipfs.files.add(smallFile.data, done)) + + it('stat outside of mfs', function (done) { + if (!withGo) { + console.log('Not supported in js-ipfs yet') + this.skip() + } + + ipfs.files.stat('/ipfs/' + smallFile.cid, (err, stat) => { + expect(err).to.not.exist() + expect(stat).to.eql({ + type: 'file', + blocks: 0, + size: 12, + hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', + cumulativeSize: 20, + withLocality: false, + local: undefined, + sizeLocal: undefined + }) + done() + }) + }) + }) }) }