Skip to content

Commit 40cf00f

Browse files
committed
code cleanup and pin utils tests
1 parent f5a05fe commit 40cf00f

File tree

10 files changed

+281
-156
lines changed

10 files changed

+281
-156
lines changed

src/cli/commands/pin/add.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
const paths = argv['ipfs-path'].split(' ')
1919
const recursive = argv.recursive
2020
const type = recursive ? 'recursive' : 'direct'
21-
argv.ipfs.pin.add(paths[0], { recursive }, (err, results) => {
21+
argv.ipfs.pin.add(paths[0], { recursive: recursive }, (err, results) => {
2222
if (err) { throw err }
2323
results.forEach((res) => {
2424
console.log(`pinned ${res.hash} ${type}ly`)

src/cli/commands/pin/ls.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = {
2929
const paths = argv.path && argv.path.split(' ')
3030
const type = argv.type
3131
const quiet = argv.quiet
32-
argv.ipfs.pin.ls(paths, { type }, (err, results) => {
32+
argv.ipfs.pin.ls(paths, { type: type }, (err, results) => {
3333
if (err) { throw err }
3434
results.forEach((res) => {
3535
let line = res.hash

src/cli/commands/pin/rm.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = {
1717
handler: (argv) => {
1818
const paths = argv['ipfs-path'].split(' ')
1919
const recursive = argv.recursive
20-
argv.ipfs.pin.rm(paths, { recursive }, (err, results) => {
20+
argv.ipfs.pin.rm(paths, { recursive: recursive }, (err, results) => {
2121
if (err) { throw err }
2222
results.forEach((res) => {
2323
console.log(`unpinned ${res.hash}`)

src/core/components/dag.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ module.exports = function dag (self) {
7777
)
7878
}),
7979

80-
getRecursive: promisify((multihash, callback) => {
80+
// TODO - move to IPLD resolver and generalize to other IPLD formats
81+
_getRecursive: promisify((multihash, callback) => {
8182
// gets flat array of all DAGNodes in tree given by multihash
8283
callback = once(callback)
8384
self.dag.get(new CID(multihash), (err, res) => {
@@ -90,7 +91,7 @@ module.exports = function dag (self) {
9091
}
9192
// branch case
9293
links.forEach(link => {
93-
self.dag.getRecursive(link.multihash, (err, subNodes) => {
94+
self.dag._getRecursive(link.multihash, (err, subNodes) => {
9495
if (err) { return callback(err) }
9596
nodes.push(subNodes)
9697
if (nodes.length === links.length + 1) {

src/core/components/pin-set.js

+15-25
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ exports = module.exports = function (dag) {
6565
hasChild: (root, childhash, callback, _links, _checked, _seen) => {
6666
// callback (err, has)
6767
callback = once(callback)
68-
if (callback.called) { return }
6968
if (typeof childhash === 'object') {
7069
childhash = toB58String(childhash)
7170
}
@@ -83,9 +82,7 @@ exports = module.exports = function (dag) {
8382
return callback(null, true)
8483
}
8584
dag.get(new CID(link.multihash), (err, res) => {
86-
if (err) {
87-
return callback(err)
88-
}
85+
if (err) { return callback(err) }
8986
// don't check the same links twice
9087
if (bs58link in _seen) { return }
9188
_seen[bs58link] = true
@@ -180,15 +177,9 @@ exports = module.exports = function (dag) {
180177
hashed[h].push(items[i])
181178
}
182179
const storeItemsCb = (err, child) => {
183-
if (callback.called) { return }
184-
if (err) {
185-
return callback(err)
186-
}
180+
if (err) { return callback(err) }
187181
dag.put(child, (err) => {
188-
if (callback.called) { return }
189-
if (err) {
190-
return callback(err)
191-
}
182+
if (err) { return callback(err) }
192183
logInternalKey(child.multihash)
193184
rootLinks[this.h] = new DAGLink(
194185
'', child.size, child.multihash
@@ -203,19 +194,18 @@ exports = module.exports = function (dag) {
203194
}
204195
})
205196
}
206-
_subcalls += Object.keys(hashed).length
207-
for (let h in hashed) {
208-
if (hashed.hasOwnProperty(h)) {
209-
pinSet.storeItems(
210-
hashed[h],
211-
logInternalKey,
212-
storeItemsCb.bind({h: h}),
213-
_depth + 1,
214-
_subcalls,
215-
_done
216-
)
217-
}
218-
}
197+
const hashedKeys = Object.keys(hashed)
198+
_subcalls += hashedKeys.length
199+
hashedKeys.forEach(h => {
200+
pinSet.storeItems(
201+
hashed[h],
202+
logInternalKey,
203+
storeItemsCb.bind({h: h}),
204+
_depth + 1,
205+
_subcalls,
206+
_done
207+
)
208+
})
219209
}
220210
},
221211

0 commit comments

Comments
 (0)