@@ -331,17 +331,38 @@ class FuseManager extends EventEmitter {
331
331
}
332
332
}
333
333
334
- async unmount ( ) {
334
+ async unmount ( mnt ) {
335
335
await ensureFuse ( )
336
+ const self = this
336
337
337
- if ( ! this . _rootMnt ) return
338
+ if ( ! this . _rootMnt ) throw new Error ( 'Cannot unmount if the root drive is not mounted.' )
338
339
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 ( )
341
342
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
+ }
345
366
}
346
367
347
368
async mountDrive ( path , opts ) {
@@ -415,8 +436,11 @@ function createFuseHandlers (fuseManager) {
415
436
} ,
416
437
417
438
unmount : async ( call ) => {
439
+ const mnt = call . request . getPath ( )
440
+
441
+ await fuseManager . unmount ( mnt )
442
+
418
443
const rsp = rpc . fuse . messages . UnmountResponse ( )
419
- await fuseManager . unmount ( )
420
444
return rsp
421
445
} ,
422
446
0 commit comments