-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.js
More file actions
80 lines (70 loc) · 1.61 KB
/
Copy pathindex.js
File metadata and controls
80 lines (70 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const Fuse = require('fuse-bindings')
const debug = require('debug')('ipfs-fuse:index')
const IpfsApi = require('ipfs-http-client')
const mkdirp = require('mkdirp')
const Async = require('async')
const explain = require('explain-error')
const createIpfsFuse = require('./ipfs-fuse')
exports.mount = (mountPath, opts, cb) => {
if (!cb) {
cb = opts
opts = {}
}
opts = opts || {}
cb = cb || (() => {})
Async.auto({
path (cb) {
if (process.platform === 'win32') {
cb()
return
}
mkdirp(mountPath, (err) => {
if (err) {
err = explain(err, 'Failed to create mount point')
debug(err)
return cb(err)
}
cb()
})
},
ipfs (cb) {
const ipfs = new IpfsApi(opts.ipfs)
ipfs.id((err, id) => {
if (err) {
err = explain(err, 'Failed to connect to IPFS node')
debug(err)
return cb(err)
}
debug(id)
cb(null, ipfs)
})
},
mount: ['path', 'ipfs', (res, cb) => {
Fuse.mount(mountPath, createIpfsFuse(res.ipfs), opts.fuse, (err) => {
if (err) {
err = explain(err, 'Failed to mount IPFS FUSE volume')
debug(err)
return cb(err)
}
cb(null, {})
})
}]
}, (err) => {
if (err) {
debug(err)
return cb(err)
}
cb(null, {})
})
}
exports.unmount = (mountPath, cb) => {
cb = cb || (() => {})
Fuse.unmount(mountPath, (err) => {
if (err) {
err = explain(err, 'Failed to unmount IPFS FUSE volume')
debug(err)
return cb(err)
}
cb()
})
}