Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
fix: update to newest IPLD libraries
Browse files Browse the repository at this point in the history
ipld-dag-pb got a new release with breaking changes, update to that release.
  • Loading branch information
vmx authored and achingbrain committed Aug 5, 2019
1 parent c9c74de commit c21e032
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 51 deletions.
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
"detect-node": "^2.0.4",
"detect-webworker": "^1.0.0",
"dirty-chai": "^2.0.1",
"ipfs-block-service": "~0.15.2",
"ipfs-repo": "~0.26.4",
"ipld": "~0.24.0",
"ipfs-block-service": "~0.16.0",
"ipfs-repo": "~0.27.0",
"ipld": "~0.25.0",
"memdown": "^4.0.0",
"temp-write": "^3.4.0"
},
Expand All @@ -58,18 +58,17 @@
"debug": "^4.1.0",
"err-code": "^1.1.2",
"hamt-sharding": "~0.0.2",
"interface-datastore": "~0.6.0",
"interface-datastore": "~0.7.0",
"ipfs-multipart": "~0.1.0",
"ipfs-unixfs": "~0.1.16",
"ipfs-unixfs-exporter": "~0.37.6",
"ipfs-unixfs-importer": "~0.39.9",
"ipld-dag-pb": "~0.17.2",
"ipld-dag-pb": "~0.18.0",
"joi-browser": "^13.4.0",
"mortice": "^1.2.1",
"multicodec": "~0.5.3",
"multihashes": "~0.4.14",
"once": "^1.4.0",
"promisify-es6": "^1.0.3",
"pull-stream": "^3.6.9"
},
"contributors": [
Expand Down
20 changes: 2 additions & 18 deletions src/core/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const assert = require('assert')
const promisify = require('promisify-es6')
const createLock = require('./utils/create-lock')

// These operations are read-locked at the function level and will execute simultaneously
Expand Down Expand Up @@ -48,24 +47,9 @@ module.exports = (options) => {
assert(options.blocks, 'MFS requires an BlockStore instance')
assert(options.datastore, 'MFS requires a DataStore instance')

// should be able to remove this when async/await PRs are in for datastore, blockstore & repo
options.repo = {
blocks: {
get: promisify(options.blocks.get, {
context: options.blocks
})
},
datastore: {
open: promisify(options.datastore.open, {
context: options.datastore
}),
get: promisify(options.datastore.get, {
context: options.datastore
}),
put: promisify(options.datastore.put, {
context: options.datastore
})
}
blocks: options.blocks,
datastore: options.datastore
}

const lock = createLock(repoOwner)
Expand Down
16 changes: 7 additions & 9 deletions src/core/utils/add-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,21 @@ const convertToShardedDirectory = async (context, options) => {
}

const addToDirectory = async (context, options) => {
let parent = await DAGNode.rmLink(options.parent, options.name)
parent = await DAGNode.addLink(parent, new DAGLink(options.name, options.size, options.cid))
options.parent.rmLink(options.name)
options.parent.addLink(new DAGLink(options.name, options.size, options.cid))

const format = mc[options.format.toUpperCase().replace(/-/g, '_')]
const hashAlg = mh.names[options.hashAlg]

// Persist the new parent DAGNode
const cid = await context.ipld.put(parent, format, {
const cid = await context.ipld.put(options.parent, format, {
cidVersion: options.cidVersion,
hashAlg,
hashOnly: !options.flush
})

return {
node: parent,
node: options.parent,
cid
}
}
Expand All @@ -120,15 +120,13 @@ const addToShardedDirectory = async (context, options) => {
const newLink = result.node.Links
.find(link => link.Name.substring(0, 2) === path[0].prefix)

let parent = options.parent

if (oldLink) {
parent = await DAGNode.rmLink(options.parent, oldLink.Name)
options.parent.rmLink(oldLink.Name)
}

parent = await DAGNode.addLink(parent, newLink)
options.parent.addLink(newLink)

return updateHamtDirectory(context, parent.Links, path[0].bucket, options)
return updateHamtDirectory(context, options.parent.Links, path[0].bucket, options)
}

const addFileToShardedDirectory = async (context, options) => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/create-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const createNode = async (context, type, options) => {
const format = mc[options.format.toUpperCase().replace(/-/g, '_')]
const hashAlg = mh.names[options.hashAlg]

const node = DAGNode.create(new UnixFS(type).marshal())
const node = new DAGNode(new UnixFS(type).marshal())
const cid = await context.ipld.put(node, format, {
cidVersion: options.cidVersion,
hashAlg
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/hamt-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const updateHamtDirectory = async (context, links, bucket, options) => {
const format = mc[options.format.toUpperCase().replace(/-/g, '_')]
const hashAlg = mh.names[options.hashAlg]

const parent = DAGNode.create(dir.marshal(), links)
const parent = new DAGNode(dir.marshal(), links)
const cid = await context.ipld.put(parent, format, {
cidVersion: options.cidVersion,
hashAlg,
Expand Down
14 changes: 7 additions & 7 deletions src/core/utils/remove-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ const removeFromDirectory = async (context, options) => {
const format = mc[options.format.toUpperCase().replace(/-/g, '_')]
const hashAlg = mh.names[options.hashAlg]

const newParentNode = await DAGNode.rmLink(options.parent, options.name)
const cid = await context.ipld.put(newParentNode, format, {
options.parent.rmLink(options.name)
const cid = await context.ipld.put(options.parent, format, {
cidVersion: options.cidVersion,
hashAlg
})

log(`Updated regular directory ${cid}`)

return {
node: newParentNode,
node: options.parent,
cid
}
}
Expand Down Expand Up @@ -104,11 +104,11 @@ const updateShard = async (context, positions, child, options) => {
if (link.Name === `${prefix}${child.name}`) {
log(`Removing existing link ${link.Name}`)

const newNode = await DAGNode.rmLink(node, link.Name)
node.rmLink(link.Name)

await bucket.del(child.name)

return updateHamtDirectory(context, newNode.Links, bucket, options)
return updateHamtDirectory(context, node.Links, bucket, options)
}

log(`Descending into sub-shard ${link.Name} for ${prefix}${child.name}`)
Expand All @@ -135,8 +135,8 @@ const updateShard = async (context, positions, child, options) => {
}

const updateShardParent = async (context, bucket, parent, oldName, newName, size, cid, options) => {
parent = await DAGNode.rmLink(parent, oldName)
parent = await DAGNode.addLink(parent, new DAGLink(newName, size, cid))
parent.rmLink(oldName)
parent.addLink(new DAGLink(newName, size, cid))

return updateHamtDirectory(context, parent.Links, bucket, options)
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/with-mfs-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const loadMfsRoot = async (context) => {
}

log('Creating new MFS root')
const node = DAGNode.create(new UnixFs('directory').marshal())
const node = new DAGNode(new UnixFs('directory').marshal())
cid = await context.ipld.put(node, mc.DAG_PB, {
cidVersion: 0,
hashAlg: mh.names['sha2-256'] // why can't ipld look this up?
Expand Down
8 changes: 0 additions & 8 deletions test/helpers/create-mfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const core = require('../../src/core')
const isWebWorker = require('detect-webworker')
const promisify = require('promisify-es6')
const {
MemoryDatastore
} = require('interface-datastore')
Expand All @@ -21,13 +20,6 @@ const createMfs = async () => {
}
})

repo.init = promisify(repo.init, {
context: repo
})
repo.open = promisify(repo.open, {
context: repo
})

await repo.init({})
await repo.open()

Expand Down

0 comments on commit c21e032

Please sign in to comment.