File tree Expand file tree Collapse file tree 5 files changed +94
-1
lines changed Expand file tree Collapse file tree 5 files changed +94
-1
lines changed Original file line number Diff line number Diff line change 86
86
"hapi" : " ^16.6.2" ,
87
87
"hat" : " 0.0.3" ,
88
88
"ipfs-api" : " ^21.0.0" ,
89
+ "ipfs-repo" : " ~0.20.0" ,
89
90
"joi" : " ^13.1.2" ,
90
91
"lodash.clone" : " ^4.5.0" ,
91
92
"lodash.defaults" : " ^4.2.0" ,
Original file line number Diff line number Diff line change 2
2
3
3
const multiaddr = require ( 'multiaddr' )
4
4
const defaultsDeep = require ( 'lodash.defaultsdeep' )
5
+ const createRepo = require ( './utils/repo/create-nodejs' )
5
6
const defaults = require ( 'lodash.defaults' )
6
7
const waterfall = require ( 'async/waterfall' )
7
8
const debug = require ( 'debug' )
@@ -30,6 +31,7 @@ class Node extends EventEmitter {
30
31
31
32
this . opts . args = this . opts . args || [ ]
32
33
this . path = this . opts . repoPath
34
+ this . repo = createRepo ( this . path )
33
35
this . disposable = this . opts . disposable
34
36
this . clean = true
35
37
this . _apiAddr = null
@@ -62,7 +64,7 @@ class Node extends EventEmitter {
62
64
} )
63
65
64
66
this . exec = new IPFS ( {
65
- repo : this . path ,
67
+ repo : this . repo ,
66
68
init : false ,
67
69
start : false ,
68
70
pass : this . opts . pass ,
Original file line number Diff line number Diff line change
1
+ /* global self */
2
+ 'use strict'
3
+
4
+ const IPFSRepo = require ( 'ipfs-repo' )
5
+ const hat = require ( 'hat' )
6
+
7
+ const idb = self . indexedDB ||
8
+ self . mozIndexedDB ||
9
+ self . webkitIndexedDB ||
10
+ self . msIndexedDB
11
+
12
+ function createTempRepo ( repoPath ) {
13
+ repoPath = repoPath || '/ipfs-' + hat ( )
14
+
15
+ const repo = new IPFSRepo ( repoPath )
16
+
17
+ repo . teardown = ( done ) => {
18
+ repo . close ( ( ) => {
19
+ idb . deleteDatabase ( repoPath )
20
+ idb . deleteDatabase ( repoPath + '/blocks' )
21
+ done ( )
22
+ } )
23
+ }
24
+
25
+ return repo
26
+ }
27
+
28
+ module . exports = createTempRepo
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const IPFSRepo = require ( 'ipfs-repo' )
4
+ const os = require ( 'os' )
5
+ const path = require ( 'path' )
6
+ const hat = require ( 'hat' )
7
+ const series = require ( 'async/series' )
8
+ const rimraf = require ( 'rimraf' )
9
+ const fs = require ( 'fs' )
10
+
11
+ const clean = ( dir ) => {
12
+ try {
13
+ fs . accessSync ( dir )
14
+ } catch ( err ) {
15
+ // Does not exist so all good
16
+ return
17
+ }
18
+
19
+ rimraf . sync ( dir )
20
+ }
21
+
22
+ function createTempRepo ( repoPath ) {
23
+ repoPath = repoPath || path . join ( os . tmpdir ( ) , '/ipfs-test-' + hat ( ) )
24
+
25
+ const repo = new IPFSRepo ( repoPath )
26
+
27
+ repo . teardown = ( done ) => {
28
+ series ( [
29
+ // ignore err, might have been closed already
30
+ ( cb ) => repo . close ( ( ) => cb ( ) ) ,
31
+ ( cb ) => {
32
+ clean ( repoPath )
33
+ cb ( )
34
+ }
35
+ ] , done )
36
+ }
37
+
38
+ return repo
39
+ }
40
+
41
+ module . exports = createTempRepo
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ const path = require('path')
13
13
const flatten = require ( '../src/utils/flatten' )
14
14
const tempDir = require ( '../src/utils/tmp-dir' )
15
15
const findIpfsExecutable = require ( '../src/utils/find-ipfs-executable' )
16
+ const createRepo = require ( '../src/utils/repo/create-nodejs' )
16
17
17
18
const IPFSRepo = require ( 'ipfs-repo' )
18
19
@@ -62,5 +63,25 @@ describe('utils', () => {
62
63
expect ( fs . existsSync ( execPath ) ) . to . be . ok ( )
63
64
} )
64
65
} )
66
+
67
+ describe ( '.createRepo' , ( ) => {
68
+ let repo = null
69
+ let repoPath = tempDir ( )
70
+
71
+ it ( 'should create repo' , ( ) => {
72
+ repo = createRepo ( repoPath )
73
+ expect ( repo ) . to . exist ( )
74
+ expect ( repo ) . to . be . instanceOf ( IPFSRepo )
75
+ expect ( fs . existsSync ( repoPath ) ) . to . be . ok ( )
76
+ } )
77
+
78
+ it ( 'should cleanup repo' , ( done ) => {
79
+ repo . teardown ( ( err ) => {
80
+ expect ( err ) . to . not . exist ( )
81
+ expect ( ! fs . existsSync ( repoPath ) ) . to . be . ok ( )
82
+ done ( )
83
+ } )
84
+ } )
85
+ } )
65
86
}
66
87
} )
You can’t perform that action at this time.
0 commit comments