From afd32553b407c8e5e456b72e5f1bf5401d3a2ca6 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 15 Aug 2018 16:20:31 +0100 Subject: [PATCH] fix: object.patch.rmLink not working (#1508) This PR contains fixes for the test failures that are happening in master for `object.patch.rmLink`. I **think** this change https://github.com/ipld/js-ipld-dag-pb/pull/80 made `DAGLink` validate the hash better and caused the failures to start. It also contains fixes for the `pinSet` module which was using the "private" `_multihash` property which was removed in https://github.com/ipld/js-ipld-dag-pb/pull/81 and released 2 days ago - don't use private APIs kids. License: MIT Signed-off-by: Alan Shaw --- src/cli/commands/object/patch/rm-link.js | 8 +------- src/core/components/pin-set.js | 2 +- src/http/api/resources/object.js | 6 +++--- test/core/pin-set.js | 4 ++-- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/cli/commands/object/patch/rm-link.js b/src/cli/commands/object/patch/rm-link.js index cac1666ce3..dde69c30f8 100644 --- a/src/cli/commands/object/patch/rm-link.js +++ b/src/cli/commands/object/patch/rm-link.js @@ -1,6 +1,5 @@ 'use strict' -const DAGLink = require('ipld-dag-pb').DAGLink const debug = require('debug') const log = debug('cli:object') log.error = debug('cli:object:error') @@ -14,12 +13,7 @@ module.exports = { builder: {}, handler (argv) { - // TODO rmLink should support removing by name and/or multihash - // without having to know everything, which in fact it does, however, - // since it expectes a DAGLink type, we have to pass some fake size and - // hash. - const link = new DAGLink(argv.link, 1, 'Qm') - argv.ipfs.object.patch.rmLink(argv.root, link, { + argv.ipfs.object.patch.rmLink(argv.root, { name: argv.link }, { enc: 'base58' }, (err, node) => { if (err) { diff --git a/src/core/components/pin-set.js b/src/core/components/pin-set.js index 1c816d993c..d100b85311 100644 --- a/src/core/components/pin-set.js +++ b/src/core/components/pin-set.js @@ -168,7 +168,7 @@ exports = module.exports = function (dag) { function storeChild (err, child, binIdx, cb) { if (err) { return cb(err) } - const opts = { cid: new CID(child._multihash), preload: false } + const opts = { cid: new CID(child.multihash), preload: false } dag.put(child, opts, err => { if (err) { return cb(err) } fanoutLinks[binIdx] = new DAGLink('', child.size, child.multihash) diff --git a/src/http/api/resources/object.js b/src/http/api/resources/object.js index 16f5db9c8d..9f9e7f2e32 100644 --- a/src/http/api/resources/object.js +++ b/src/http/api/resources/object.js @@ -520,7 +520,7 @@ exports.patchRmLink = { if (!request.query.arg[1]) { return reply({ - Message: 'cannot create link with no name!', + Message: 'cannot remove link with no name!', Code: 0 }).code(500).takeover() } @@ -545,11 +545,11 @@ exports.patchRmLink = { const link = request.pre.args.link const ipfs = request.server.app.ipfs - ipfs.object.patch.rmLink(root, link, (err, node) => { + ipfs.object.patch.rmLink(root, { name: link }, (err, node) => { if (err) { log.error(err) return reply({ - Message: 'Failed to add link to object: ' + err, + Message: 'Failed to remove link from object: ' + err, Code: 0 }).code(500) } diff --git a/test/core/pin-set.js b/test/core/pin-set.js index 33b50ad144..64b8fb1389 100644 --- a/test/core/pin-set.js +++ b/test/core/pin-set.js @@ -31,7 +31,7 @@ function createNodes (num, callback) { const items = [] for (let i = 0; i < num; i++) { items.push(cb => - createNode(String(i), (err, node) => cb(err, node._multihash)) + createNode(String(i), (err, node) => cb(err, node.multihash)) ) } @@ -73,7 +73,7 @@ describe('pinSet', function () { createNode('data', (err, node) => { expect(err).to.not.exist() - const nodeHash = node._multihash + const nodeHash = node.multihash pinSet.storeSet([nodeHash], (err, rootNode) => { expect(err).to.not.exist() const node = rootNode.toJSON()