Skip to content

Commit

Permalink
code cleanup and pin utils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamStone committed Feb 24, 2018
1 parent f5a05fe commit 40cf00f
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 156 deletions.
2 changes: 1 addition & 1 deletion src/cli/commands/pin/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
const paths = argv['ipfs-path'].split(' ')
const recursive = argv.recursive
const type = recursive ? 'recursive' : 'direct'
argv.ipfs.pin.add(paths[0], { recursive }, (err, results) => {
argv.ipfs.pin.add(paths[0], { recursive: recursive }, (err, results) => {
if (err) { throw err }
results.forEach((res) => {
console.log(`pinned ${res.hash} ${type}ly`)
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/pin/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
const paths = argv.path && argv.path.split(' ')
const type = argv.type
const quiet = argv.quiet
argv.ipfs.pin.ls(paths, { type }, (err, results) => {
argv.ipfs.pin.ls(paths, { type: type }, (err, results) => {
if (err) { throw err }
results.forEach((res) => {
let line = res.hash
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/pin/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
handler: (argv) => {
const paths = argv['ipfs-path'].split(' ')
const recursive = argv.recursive
argv.ipfs.pin.rm(paths, { recursive }, (err, results) => {
argv.ipfs.pin.rm(paths, { recursive: recursive }, (err, results) => {
if (err) { throw err }
results.forEach((res) => {
console.log(`unpinned ${res.hash}`)
Expand Down
5 changes: 3 additions & 2 deletions src/core/components/dag.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ module.exports = function dag (self) {
)
}),

getRecursive: promisify((multihash, callback) => {
// TODO - move to IPLD resolver and generalize to other IPLD formats
_getRecursive: promisify((multihash, callback) => {
// gets flat array of all DAGNodes in tree given by multihash
callback = once(callback)
self.dag.get(new CID(multihash), (err, res) => {
Expand All @@ -90,7 +91,7 @@ module.exports = function dag (self) {
}
// branch case
links.forEach(link => {
self.dag.getRecursive(link.multihash, (err, subNodes) => {
self.dag._getRecursive(link.multihash, (err, subNodes) => {
if (err) { return callback(err) }
nodes.push(subNodes)
if (nodes.length === links.length + 1) {
Expand Down
40 changes: 15 additions & 25 deletions src/core/components/pin-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ exports = module.exports = function (dag) {
hasChild: (root, childhash, callback, _links, _checked, _seen) => {
// callback (err, has)
callback = once(callback)
if (callback.called) { return }
if (typeof childhash === 'object') {
childhash = toB58String(childhash)
}
Expand All @@ -83,9 +82,7 @@ exports = module.exports = function (dag) {
return callback(null, true)
}
dag.get(new CID(link.multihash), (err, res) => {
if (err) {
return callback(err)
}
if (err) { return callback(err) }
// don't check the same links twice
if (bs58link in _seen) { return }
_seen[bs58link] = true
Expand Down Expand Up @@ -180,15 +177,9 @@ exports = module.exports = function (dag) {
hashed[h].push(items[i])
}
const storeItemsCb = (err, child) => {
if (callback.called) { return }
if (err) {
return callback(err)
}
if (err) { return callback(err) }
dag.put(child, (err) => {
if (callback.called) { return }
if (err) {
return callback(err)
}
if (err) { return callback(err) }
logInternalKey(child.multihash)
rootLinks[this.h] = new DAGLink(
'', child.size, child.multihash
Expand All @@ -203,19 +194,18 @@ exports = module.exports = function (dag) {
}
})
}
_subcalls += Object.keys(hashed).length
for (let h in hashed) {
if (hashed.hasOwnProperty(h)) {
pinSet.storeItems(
hashed[h],
logInternalKey,
storeItemsCb.bind({h: h}),
_depth + 1,
_subcalls,
_done
)
}
}
const hashedKeys = Object.keys(hashed)
_subcalls += hashedKeys.length
hashedKeys.forEach(h => {
pinSet.storeItems(
hashed[h],
logInternalKey,
storeItemsCb.bind({h: h}),
_depth + 1,
_subcalls,
_done
)
})
}
},

Expand Down
Loading

0 comments on commit 40cf00f

Please sign in to comment.