Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: object.patch.rmLink not working (#1508)
Browse files Browse the repository at this point in the history
This PR contains fixes for the test failures that are happening in master for `object.patch.rmLink`.

I **think** this change ipld/js-ipld-dag-pb#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 ipld/js-ipld-dag-pb#81 and released 2 days ago - don't use private APIs kids.

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
  • Loading branch information
alanshaw authored Aug 15, 2018
1 parent 59bc6d5 commit afd3255
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
8 changes: 1 addition & 7 deletions src/cli/commands/object/patch/rm-link.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/pin-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/http/api/resources/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions test/core/pin-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
}

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit afd3255

Please sign in to comment.