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

fix: object.patch.rmLink not working #1508

Merged
merged 2 commits into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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