Browse Source

use latest hyperdrive-fuse

Kieran Gibb 1 year ago
parent
commit
c4d3b2fc57
No account linked to committer's email address
4 changed files with 44 additions and 2357 deletions
  1. 1
    1
      index.js
  2. 2
    2
      package.json
  3. 41
    27
      test/index.test.js
  4. 0
    2327
      yarn.lock

+ 1
- 1
index.js View File

@@ -4,7 +4,7 @@ const mkdirp = require('mkdirp')
4 4
 const maybe = require('call-me-maybe')
5 5
 const Fuse = require('fuse-native')
6 6
 
7
-module.exports = function mount (drive, dir, opts, cb) {
7
+module.exports = function mount (drive, dir, opts = {}, cb) {
8 8
   if ((typeof opts === 'function') && !cb) return mount(drive, dir, {}, opts)
9 9
 
10 10
   return maybe(cb, new Promise((resolve, reject) => {

+ 2
- 2
package.json View File

@@ -11,14 +11,14 @@
11 11
   "dependencies": {
12 12
     "call-me-maybe": "^1.0.1",
13 13
     "debug": "^4.1.1",
14
-    "hyperdrive-fuse": "1.2.1",
14
+    "hyperdrive-fuse": "^1.2.16",
15 15
     "mkdirp": "^0.5.1",
16 16
     "rimraf": "^2.6.3"
17 17
   },
18 18
   "devDependencies": {
19 19
     "hyperdrive": "^10.3.2",
20 20
     "random-access-memory": "^3.1.1",
21
-    "kappa-drive": "2.0.2-alpha1",
21
+    "kappa-drive": "git+https://gitlab.com/coboxcoop/kappa-drive.git",
22 22
     "tap-spec": "^5.0.0",
23 23
     "tape": "^4.11.0",
24 24
     "tape-plus": "^1.0.0",

+ 41
- 27
test/index.test.js View File

@@ -454,30 +454,37 @@ describe('mount', (context) => {
454 454
     var storage = {}
455 455
     var unmount = {}
456 456
 
457
-    function setup (drive, colour, cb) {
458
-      storage[colour] = tmp()
459
-      mount(drive, storage[colour], (err, unmountFn) => {
460
-        assert.error(err, 'no error when mounting')
461
-        unmount[colour] = unmountFn
462
-        drive.ready(cb)
463
-      })
464
-    }
465
-
466 457
     setup(orangeDrive, 'orange', function () {
467 458
       setup(blueDrive, 'blue', function () {
468 459
         run(`mkdir ${storage.orange}/cabbage`, (err, output) => {
469 460
           assert.error(err, 'no error on mkdir')
470
-          // 'seed' the blue drive with a file (TODO this is a hack)
471
-          run(`echo "this file is not needed" > ${storage.blue}/blue.txt`, (err, output) => {
472
-            assert.error(err, 'no error on echo to file')
473
-            replicate(orangeDrive, blueDrive, check)
474
-          })
461
+          sync(check)
475 462
         })
476 463
       })
477 464
     })
478 465
 
479
-    function check (err) {
480
-      assert.error(err, 'no error on replicate')
466
+    function sync (cb) {
467
+      orangeDrive.ready(() => blueDrive.ready(() => {
468
+        replicate(orangeDrive, blueDrive, (err) => {
469
+          assert.error(err, 'no error on replicate')
470
+          orangeDrive.ready(() => blueDrive.ready(cb))
471
+        })
472
+      }))
473
+    }
474
+
475
+    function setup (drive, colour, cb) {
476
+      storage[colour] = tmp()
477
+      drive.ready((err) => {
478
+        assert.error(err, 'no error on ready')
479
+        mount(drive, storage[colour], (err, unmountFn) => {
480
+          assert.error(err, 'no error when mounting')
481
+          unmount[colour] = unmountFn
482
+          cb()
483
+        })
484
+      })
485
+    }
486
+
487
+    function check () {
481 488
       run(`ls ${storage.blue}`, (err, output) => {
482 489
         assert.error(err, 'no error on ls')
483 490
         assert.true(output[0].split('\n').indexOf('cabbage') > -1, 'dir successfully replicated')
@@ -486,20 +493,21 @@ describe('mount', (context) => {
486 493
           run(`ls ${storage.blue}`, (err, output) => {
487 494
             assert.error(err, 'error on ls')
488 495
             assert.false(output[0].split('\n').indexOf('cabbage') > -1, 'ls no longer lists dir')
489
-            replicate(orangeDrive, blueDrive, (err) => {
490
-              assert.error(err, 'no error on replicate')
491
-              run(`ls ${storage.orange}`, (err, output) => {
492
-                assert.error(err, 'no error')
493
-                assert.false(output[0].split('\n').indexOf('cabbage') > -1, 'ls no longer lists dir')
494
-                unmount.orange(() => {
495
-                  unmount.blue(next)
496
-                })
497
-              })
498
-            })
496
+            sync(checkAgain)
499 497
           })
500 498
         })
501 499
       })
502 500
     }
501
+
502
+    function checkAgain () {
503
+      run(`ls ${storage.orange}`, (err, output) => {
504
+        assert.error(err, 'no error')
505
+        assert.false(output[0].split('\n').indexOf('cabbage') > -1, 'ls no longer lists dir')
506
+        unmount.orange(() => {
507
+          unmount.blue(next)
508
+        })
509
+      })
510
+    }
503 511
   })
504 512
 
505 513
   context("replicate - attempt to mkdir another peer's existing directory - using unix commands", (assert, next) => {
@@ -531,13 +539,19 @@ describe('mount', (context) => {
531 539
             // 'seed' the blue drive with a file (TODO this is a hack)
532 540
             run(`echo "this file is not needed" > ${storage.blue}/blue.txt`, (err, output) => {
533 541
               assert.error(err, 'no error on echo to file')
534
-              replicate(orangeDrive, blueDrive, check)
542
+              sync(check)
535 543
             })
536 544
           })
537 545
         })
538 546
       })
539 547
     })
540 548
 
549
+    function sync (cb) { 
550
+      replicate(orangeDrive, blueDrive, () => {
551
+        orangeDrive.ready(() => blueDrive.ready(cb))
552
+      })
553
+    }
554
+
541 555
     function check (err) {
542 556
       assert.error(err, 'no error on replicate')
543 557
       run(`ls ${storage.blue}`, (err, output) => {

+ 0
- 2327
yarn.lock
File diff suppressed because it is too large
View File