Browse Source

remove extra fn, fix bug with SIGINT being passed as callback

ameba23 3 years ago
parent
commit
7c15fd0fb2
1 changed files with 18 additions and 20 deletions
  1. 18
    20
      index.js

+ 18
- 20
index.js View File

@@ -2,31 +2,29 @@ const rimraf = require('rimraf')
2 2
 const hyperfuse = require('hyperdrive-fuse')
3 3
 const mkdirp = require('mkdirp')
4 4
 
5
-module.exports = function () {
6
-  return function mount (drive, dir, cb) {
7
-    mkdirp.sync(dir)
5
+module.exports = function mount (drive, dir, cb) {
6
+  mkdirp.sync(dir)
8 7
 
9
-    var mounting = hyperfuse.mount(drive, dir)
10
-    mounting.catch(cb)
8
+  var mounting = hyperfuse.mount(drive, dir)
9
+  mounting.catch(cb)
11 10
 
12
-    mounting.then(({ destroy }) => {
13
-      process.on('SIGINT', done)
11
+  mounting.then(({ destroy }) => {
12
+    process.on('SIGINT', done)
14 13
 
15
-      return cb(null, done)
14
+    return cb(null, done)
16 15
 
17
-      function done (callback) {
18
-        if (!callback) callback = noop
19
-        destroy((err) => {
20
-          if (err) throw err
21
-          process.removeListener('SIGINT', done)
22
-          rimraf(dir, (err) => {
23
-            if (err) return callback(err)
24
-            return callback()
25
-          })
16
+    function done (callback) {
17
+      if (typeof callback !== 'function' || !callback) callback = noop
18
+      destroy((err) => {
19
+        if (err) throw err
20
+        process.removeListener('SIGINT', done)
21
+        rimraf(dir, (err) => {
22
+          if (err) return callback(err)
23
+          return callback()
26 24
         })
27
-      }
28
-    })
29
-  }
25
+      })
26
+    }
27
+  })
30 28
 }
31 29
 
32 30
 function noop () {}