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

Commit ea8ba91

Browse files
authored
Merge pull request #25 from ipfs/update-dag-pb-to-not-have-cid-property
fix: updates ipld-dag-pb dep to version without .cid or .multihash properties
2 parents 42ae46e + fa9029d commit ea8ba91

32 files changed

+299
-317
lines changed

package.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@
4242
"detect-node": "^2.0.4",
4343
"detect-webworker": "^1.0.0",
4444
"dirty-chai": "^2.0.1",
45-
"ipfs": "~0.33.0",
45+
"ipld": "~0.20.0",
4646
"pull-buffer-stream": "^1.0.0",
47-
"tmp": "~0.0.33"
47+
"pull-traverse": "^1.0.3"
4848
},
4949
"dependencies": {
5050
"async": "^2.6.1",
51-
"blob": "~0.0.5",
5251
"cids": "~0.5.5",
5352
"debug": "^4.1.0",
54-
"file-api": "~0.10.4",
5553
"filereader-stream": "^2.0.0",
5654
"interface-datastore": "~0.6.0",
55+
"ipfs-multipart": "~0.1.0",
5756
"ipfs-unixfs": "~0.1.16",
58-
"ipfs-unixfs-engine": "~0.33.0",
57+
"ipfs-unixfs-engine": "~0.34.0",
58+
"ipld-dag-pb": "~0.15.0",
5959
"is-pull-stream": "~0.0.0",
6060
"is-stream": "^1.1.0",
6161
"joi": "^14.0.4",
@@ -65,11 +65,8 @@
6565
"promisify-es6": "^1.0.3",
6666
"pull-cat": "^1.1.11",
6767
"pull-defer": "~0.2.3",
68-
"pull-paramap": "^1.2.2",
69-
"pull-pushable": "^2.2.0",
7068
"pull-stream": "^3.6.9",
7169
"pull-stream-to-stream": "^1.3.4",
72-
"pull-traverse": "^1.0.3",
7370
"stream-to-pull-stream": "^1.7.2"
7471
},
7572
"contributors": [

src/core/cp.js

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const defaultOptions = {
2121
hashAlg: 'sha2-256'
2222
}
2323

24-
module.exports = (ipfs) => {
24+
module.exports = (context) => {
2525
return function mfsCp () {
2626
const args = Array.from(arguments)
2727
const {
@@ -41,74 +41,73 @@ module.exports = (ipfs) => {
4141

4242
options.parents = options.p || options.parents
4343

44-
traverseTo(ipfs, destination.path, {}, (error, result) => {
44+
traverseTo(context, destination.path, {}, (error, result) => {
4545
if (error) {
4646
if (sources.length === 1) {
4747
log('Only one source, copying to a file')
48-
return copyToFile(ipfs, sources.pop(), destination, options, callback)
48+
return copyToFile(context, sources.pop(), destination, options, callback)
4949
} else {
5050
log('Multiple sources, copying to a directory')
51-
return copyToDirectory(ipfs, sources, destination, options, callback)
51+
return copyToDirectory(context, sources, destination, options, callback)
5252
}
5353
}
5454

5555
const meta = UnixFs.unmarshal(result.node.data)
5656

5757
if (meta.type === 'directory') {
58-
return copyToDirectory(ipfs, sources, destination, options, callback)
58+
return copyToDirectory(context, sources, destination, options, callback)
5959
}
6060

6161
callback(new Error('directory already has entry by that name'))
6262
})
6363
}
6464
}
6565

66-
const copyToFile = (ipfs, source, destination, options, callback) => {
66+
const copyToFile = (context, source, destination, options, callback) => {
6767
waterfall([
6868
(cb) => {
6969
parallel([
70-
(next) => stat(ipfs)(source.path, options, next),
71-
(next) => stat(ipfs)(destination.path, options, (error) => {
70+
(next) => stat(context)(source.path, options, next),
71+
(next) => stat(context)(destination.path, options, (error) => {
7272
if (!error) {
7373
return next(new Error('directory already has entry by that name'))
7474
}
7575

7676
next()
7777
}),
78-
(next) => traverseTo(ipfs, destination.dir, options, next)
78+
(next) => traverseTo(context, destination.dir, options, next)
7979
], cb)
8080
},
8181
([sourceStats, _, dest], cb) => {
8282
waterfall([
83-
(next) => addLink(ipfs, {
83+
(next) => addLink(context, {
8484
parent: dest.node,
85-
child: {
86-
size: sourceStats.cumulativeSize,
87-
hash: sourceStats.hash
88-
},
85+
size: sourceStats.cumulativeSize,
86+
cid: sourceStats.hash,
8987
name: destination.name
9088
}, next),
91-
(newParent, next) => {
92-
dest.node = newParent
93-
updateTree(ipfs, dest, next)
89+
({ node, cid }, next) => {
90+
dest.node = node
91+
dest.cid = cid
92+
updateTree(context, dest, next)
9493
},
95-
(newRoot, cb) => updateMfsRoot(ipfs, newRoot.node.multihash, cb)
94+
({ node, cid }, cb) => updateMfsRoot(context, cid, cb)
9695
], cb)
9796
}
9897
], (error) => callback(error))
9998
}
10099

101-
const copyToDirectory = (ipfs, sources, destination, options, callback) => {
100+
const copyToDirectory = (context, sources, destination, options, callback) => {
102101
waterfall([
103102
(cb) => {
104103
series([
105104
// stat in parallel
106105
(done) => parallel(
107-
sources.map(source => (next) => stat(ipfs)(source.path, options, next)),
106+
sources.map(source => (next) => stat(context)(source.path, options, next)),
108107
done
109108
),
110109
// this could end up changing the root mfs node so do it after parallel
111-
(done) => traverseTo(ipfs, destination.path, Object.assign({}, options, {
110+
(done) => traverseTo(context, destination.path, Object.assign({}, options, {
112111
createLastComponent: true
113112
}), done)
114113
], cb)
@@ -123,7 +122,7 @@ const copyToDirectory = (ipfs, sources, destination, options, callback) => {
123122
parallel(
124123
sources.map(source => {
125124
return (cb) => {
126-
stat(ipfs)(`${destination.path}/${source.name}`, options, (error) => {
125+
stat(context)(`${destination.path}/${source.name}`, options, (error) => {
127126
if (!error) {
128127
return cb(new Error('directory already has entry by that name'))
129128
}
@@ -138,30 +137,29 @@ const copyToDirectory = (ipfs, sources, destination, options, callback) => {
138137
// add links to target directory
139138
(next) => {
140139
waterfall([
141-
(done) => done(null, dest.node)
140+
(done) => done(null, dest)
142141
].concat(
143142
sourceStats.map((sourceStat, index) => {
144143
return (dest, done) => {
145-
return addLink(ipfs, {
146-
parent: dest,
147-
child: {
148-
size: sourceStat.cumulativeSize,
149-
hash: sourceStat.hash
150-
},
144+
return addLink(context, {
145+
parent: dest.node,
146+
size: sourceStat.cumulativeSize,
147+
cid: sourceStat.hash,
151148
name: sources[index].name
152149
}, done)
153150
}
154151
})
155152
), next)
156153
},
157154
// update mfs tree
158-
(newParent, next) => {
159-
dest.node = newParent
155+
({ node, cid }, next) => {
156+
dest.node = node
157+
dest.cid = cid
160158

161-
updateTree(ipfs, dest, next)
159+
updateTree(context, dest, next)
162160
},
163161
// save new root CID
164-
(newRoot, cb) => updateMfsRoot(ipfs, newRoot.node.multihash, cb)
162+
(newRoot, cb) => updateMfsRoot(context, newRoot.cid, cb)
165163
], cb)
166164
}
167165
], (error) => callback(error))

src/core/flush.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const {
88

99
const defaultOptions = {}
1010

11-
module.exports = (ipfs) => {
11+
module.exports = (context) => {
1212
return function mfsFlush (path, options, callback) {
1313
if (typeof options === 'function') {
1414
callback = options
@@ -28,7 +28,7 @@ module.exports = (ipfs) => {
2828
options = Object.assign({}, defaultOptions, options)
2929

3030
waterfall([
31-
(cb) => traverseTo(ipfs, path, {}, cb),
31+
(cb) => traverseTo(context, path, {}, cb),
3232
(root, cb) => {
3333
cb()
3434
}

src/core/index.js

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

3+
const assert = require('assert')
34
const promisify = require('promisify-es6')
45
const {
56
createLock
@@ -33,22 +34,27 @@ const unwrappedSynchronousOperations = {
3334
}
3435

3536
const wrap = ({
36-
ipfs, mfs, operations, lock
37+
options, mfs, operations, lock
3738
}) => {
3839
Object.keys(operations).forEach(key => {
39-
mfs[key] = promisify(lock(operations[key](ipfs)))
40+
mfs[key] = promisify(lock(operations[key](options)))
4041
})
4142
}
4243

4344
const defaultOptions = {
44-
repoOwner: true
45+
repoOwner: true,
46+
ipld: null,
47+
repo: null
4548
}
4649

47-
module.exports = (ipfs, options) => {
50+
module.exports = (options) => {
4851
const {
4952
repoOwner
5053
} = Object.assign({}, defaultOptions || {}, options)
5154

55+
assert(options.ipld, 'MFS requires an IPLD instance')
56+
assert(options.repo, 'MFS requires an ipfs-repo instance')
57+
5258
const lock = createLock(repoOwner)
5359

5460
const readLock = (operation) => {
@@ -62,18 +68,18 @@ module.exports = (ipfs, options) => {
6268
const mfs = {}
6369

6470
wrap({
65-
ipfs, mfs, operations: readOperations, lock: readLock
71+
options, mfs, operations: readOperations, lock: readLock
6672
})
6773
wrap({
68-
ipfs, mfs, operations: writeOperations, lock: writeLock
74+
options, mfs, operations: writeOperations, lock: writeLock
6975
})
7076

7177
Object.keys(unwrappedOperations).forEach(key => {
72-
mfs[key] = promisify(unwrappedOperations[key](ipfs))
78+
mfs[key] = promisify(unwrappedOperations[key](options))
7379
})
7480

7581
Object.keys(unwrappedSynchronousOperations).forEach(key => {
76-
mfs[key] = unwrappedSynchronousOperations[key](ipfs)
82+
mfs[key] = unwrappedSynchronousOperations[key](options)
7783
})
7884

7985
return mfs

src/core/ls.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const defaultOptions = {
1717
unsorted: false
1818
}
1919

20-
module.exports = (ipfs) => {
20+
module.exports = (context) => {
2121
return function mfsLs (path, options, callback) {
2222
if (typeof path === 'function') {
2323
callback = path
@@ -35,21 +35,21 @@ module.exports = (ipfs) => {
3535
options.long = options.l || options.long
3636

3737
waterfall([
38-
(cb) => traverseTo(ipfs, path, {}, cb),
38+
(cb) => traverseTo(context, path, {}, cb),
3939
(result, cb) => {
4040
const meta = UnixFs.unmarshal(result.node.data)
4141

4242
if (meta.type === 'directory') {
4343
map(result.node.links, (link, next) => {
4444
waterfall([
45-
(done) => loadNode(ipfs, link, done),
46-
(node, done) => {
45+
(done) => loadNode(context, link, done),
46+
({ node, cid }, done) => {
4747
const meta = UnixFs.unmarshal(node.data)
4848

4949
done(null, {
5050
name: link.name,
5151
type: meta.type,
52-
hash: formatCid(node.multihash, options.cidBase),
52+
hash: formatCid(cid, options.cidBase),
5353
size: meta.fileSize() || 0
5454
})
5555
}
@@ -59,7 +59,7 @@ module.exports = (ipfs) => {
5959
cb(null, [{
6060
name: result.name,
6161
type: meta.type,
62-
hash: formatCid(result.node.multihash, options.cidBase),
62+
hash: formatCid(result.cid, options.cidBase),
6363
size: meta.fileSize() || 0
6464
}])
6565
}

src/core/mkdir.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const defaultOptions = {
1515
cidVersion: 0
1616
}
1717

18-
module.exports = (ipfs) => {
18+
module.exports = (context) => {
1919
return function mfsMkdir (path, options, callback) {
2020
if (typeof options === 'function') {
2121
callback = options
@@ -41,7 +41,7 @@ module.exports = (ipfs) => {
4141

4242
waterfall([
4343
(cb) => {
44-
traverseTo(ipfs, path, {
44+
traverseTo(context, path, {
4545
parents: false,
4646
createLastComponent: false
4747
}, (error) => {
@@ -58,13 +58,13 @@ module.exports = (ipfs) => {
5858
return cb(error)
5959
})
6060
},
61-
(cb) => traverseTo(ipfs, path, {
61+
(cb) => traverseTo(context, path, {
6262
parents: options.parents,
6363
flush: options.flush,
6464
createLastComponent: true
6565
}, cb),
66-
(result, cb) => updateTree(ipfs, result, cb),
67-
(newRoot, next) => updateMfsRoot(ipfs, newRoot.node.multihash, next)
66+
(result, cb) => updateTree(context, result, cb),
67+
(newRoot, next) => updateMfsRoot(context, newRoot.cid, next)
6868
], (error) => {
6969
if (error && error.message.includes('file already exists') && options.parents) {
7070
// when the directory already exists and we are creating intermediate

src/core/mv.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const defaultOptions = {
1515
hashAlg: 'sha2-256'
1616
}
1717

18-
module.exports = (ipfs) => {
18+
module.exports = (context) => {
1919
return function mfsMv () {
2020
let args = Array.from(arguments)
2121

@@ -42,8 +42,8 @@ module.exports = (ipfs) => {
4242
}))
4343

4444
series([
45-
(cb) => cp(ipfs).apply(null, cpArgs.concat(cb)),
46-
(cb) => rm(ipfs).apply(null, rmArgs.concat(cb))
45+
(cb) => cp(context).apply(null, cpArgs.concat(cb)),
46+
(cb) => rm(context).apply(null, rmArgs.concat(cb))
4747
], callback)
4848
}
4949
}

0 commit comments

Comments
 (0)