Skip to content

Commit afd3255

Browse files
authored
fix: object.patch.rmLink not working (ipfs#1508)
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 <[email protected]>
1 parent 59bc6d5 commit afd3255

File tree

4 files changed

+7
-13
lines changed

4 files changed

+7
-13
lines changed

src/cli/commands/object/patch/rm-link.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict'
22

3-
const DAGLink = require('ipld-dag-pb').DAGLink
43
const debug = require('debug')
54
const log = debug('cli:object')
65
log.error = debug('cli:object:error')
@@ -14,12 +13,7 @@ module.exports = {
1413
builder: {},
1514

1615
handler (argv) {
17-
// TODO rmLink should support removing by name and/or multihash
18-
// without having to know everything, which in fact it does, however,
19-
// since it expectes a DAGLink type, we have to pass some fake size and
20-
// hash.
21-
const link = new DAGLink(argv.link, 1, 'Qm')
22-
argv.ipfs.object.patch.rmLink(argv.root, link, {
16+
argv.ipfs.object.patch.rmLink(argv.root, { name: argv.link }, {
2317
enc: 'base58'
2418
}, (err, node) => {
2519
if (err) {

src/core/components/pin-set.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ exports = module.exports = function (dag) {
168168
function storeChild (err, child, binIdx, cb) {
169169
if (err) { return cb(err) }
170170

171-
const opts = { cid: new CID(child._multihash), preload: false }
171+
const opts = { cid: new CID(child.multihash), preload: false }
172172
dag.put(child, opts, err => {
173173
if (err) { return cb(err) }
174174
fanoutLinks[binIdx] = new DAGLink('', child.size, child.multihash)

src/http/api/resources/object.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ exports.patchRmLink = {
520520

521521
if (!request.query.arg[1]) {
522522
return reply({
523-
Message: 'cannot create link with no name!',
523+
Message: 'cannot remove link with no name!',
524524
Code: 0
525525
}).code(500).takeover()
526526
}
@@ -545,11 +545,11 @@ exports.patchRmLink = {
545545
const link = request.pre.args.link
546546
const ipfs = request.server.app.ipfs
547547

548-
ipfs.object.patch.rmLink(root, link, (err, node) => {
548+
ipfs.object.patch.rmLink(root, { name: link }, (err, node) => {
549549
if (err) {
550550
log.error(err)
551551
return reply({
552-
Message: 'Failed to add link to object: ' + err,
552+
Message: 'Failed to remove link from object: ' + err,
553553
Code: 0
554554
}).code(500)
555555
}

test/core/pin-set.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function createNodes (num, callback) {
3131
const items = []
3232
for (let i = 0; i < num; i++) {
3333
items.push(cb =>
34-
createNode(String(i), (err, node) => cb(err, node._multihash))
34+
createNode(String(i), (err, node) => cb(err, node.multihash))
3535
)
3636
}
3737

@@ -73,7 +73,7 @@ describe('pinSet', function () {
7373

7474
createNode('data', (err, node) => {
7575
expect(err).to.not.exist()
76-
const nodeHash = node._multihash
76+
const nodeHash = node.multihash
7777
pinSet.storeSet([nodeHash], (err, rootNode) => {
7878
expect(err).to.not.exist()
7979
const node = rootNode.toJSON()

0 commit comments

Comments
 (0)