Skip to content

Commit ce61d4e

Browse files
committed
Updated unmount and fixed bootstrap default opts
1 parent 2bbcb74 commit ce61d4e

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,14 @@ async function start (opts = {}) {
9191

9292
const daemonOpts = {}
9393
const bootstrapOpts = opts.bootstrap || argv.bootstrap
94-
if (bootstrapOpts.length) {
94+
if (bootstrapOpts.length && bootstrapOpts[0] !== '') {
9595
if (bootstrapOpts === false && bootstrapOpts[0] === 'false') {
9696
daemonOpts.network = { bootstrap: false }
9797
} else {
9898
daemonOpts.network = { bootstrap: bootstrapOpts }
9999
}
100100
}
101+
101102
const daemon = new HyperdriveDaemon(storageRoot, daemonOpts)
102103
await daemon.ready()
103104

lib/fuse/index.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,38 @@ class FuseManager extends EventEmitter {
331331
}
332332
}
333333

334-
async unmount () {
334+
async unmount (mnt) {
335335
await ensureFuse()
336+
const self = this
336337

337-
if (!this._rootMnt) return
338+
if (!this._rootMnt) throw new Error('Cannot unmount if the root drive is not mounted.')
338339

339-
log.debug({ mnt: this._rootMnt }, 'unmounting the root drive')
340-
await hyperfuse.unmount(this._rootMnt)
340+
// If a mountpoint is not specified, then it is assumed to be the root mount.
341+
if (!mnt) return unmountRoot()
341342

342-
this._rootDrive = null
343-
this._rootMnt = null
344-
this._rootHandler = null
343+
// Otherwise, unmount the subdrive
344+
const { path, root } = this._getMountPath(mnt)
345+
if (root) return unmountRoot()
346+
return unmountSubdrive(path)
347+
348+
async function unmountRoot () {
349+
log.debug({ mnt: this._rootMnt }, 'unmounting the root drive')
350+
351+
await hyperfuse.unmount(this._rootMnt)
352+
353+
this._rootDrive = null
354+
this._rootMnt = null
355+
this._rootHandler = null
356+
}
357+
358+
function unmountSubdrive (path) {
359+
return new Promise((resolve, reject) => {
360+
this._rootDrive.unmount(path, err => {
361+
if (err) return reject(err)
362+
return resolve()
363+
})
364+
})
365+
}
345366
}
346367

347368
async mountDrive (path, opts) {
@@ -415,8 +436,11 @@ function createFuseHandlers (fuseManager) {
415436
},
416437

417438
unmount: async (call) => {
439+
const mnt = call.request.getPath()
440+
441+
await fuseManager.unmount(mnt)
442+
418443
const rsp = rpc.fuse.messages.UnmountResponse()
419-
await fuseManager.unmount()
420444
return rsp
421445
},
422446

0 commit comments

Comments
 (0)