@@ -4,6 +4,7 @@ const waterfall = require('async/waterfall')
4
4
const series = require ( 'async/series' )
5
5
const parallel = require ( 'async/parallel' )
6
6
const each = require ( 'async/each' )
7
+ const _get = require ( 'lodash.get' )
7
8
const assert = require ( 'assert' )
8
9
const path = require ( 'path' )
9
10
const debug = require ( 'debug' )
@@ -13,9 +14,11 @@ const pull = require('pull-stream')
13
14
const backends = require ( './backends' )
14
15
const version = require ( './version' )
15
16
const config = require ( './config' )
17
+ const spec = require ( './spec' )
16
18
const apiAddr = require ( './api-addr' )
17
19
const blockstore = require ( './blockstore' )
18
20
const defaultOptions = require ( './default-options' )
21
+ const defaultDatastore = require ( './default-datastore' )
19
22
const ERRORS = require ( './errors' )
20
23
21
24
const log = debug ( 'repo' )
@@ -50,6 +53,7 @@ class IpfsRepo {
50
53
this . root = backends . create ( 'root' , this . path , this . options )
51
54
this . version = version ( this . root )
52
55
this . config = config ( this . root )
56
+ this . spec = spec ( this . root )
53
57
this . apiAddr = apiAddr ( this . root )
54
58
}
55
59
@@ -65,7 +69,8 @@ class IpfsRepo {
65
69
66
70
series ( [
67
71
( cb ) => this . root . open ( ignoringAlreadyOpened ( cb ) ) ,
68
- ( cb ) => this . config . set ( config , cb ) ,
72
+ ( cb ) => this . config . set ( buildConfig ( config ) , cb ) ,
73
+ ( cb ) => this . spec . set ( buildDatastoreSpec ( config ) , cb ) ,
69
74
( cb ) => this . version . set ( repoVersion , cb )
70
75
] , callback )
71
76
}
@@ -209,6 +214,7 @@ class IpfsRepo {
209
214
parallel (
210
215
{
211
216
config : ( cb ) => this . config . exists ( cb ) ,
217
+ spec : ( cb ) => this . spec . exists ( cb ) ,
212
218
version : ( cb ) => this . version . check ( repoVersion , cb )
213
219
} ,
214
220
( err , res ) => {
@@ -377,3 +383,23 @@ function buildOptions (_options) {
377
383
378
384
return options
379
385
}
386
+
387
+ function buildConfig ( _config ) {
388
+ _config . datastore = Object . assign ( { } , defaultDatastore , _get ( _config , 'datastore' , { } ) )
389
+
390
+ return _config
391
+ }
392
+
393
+ function buildDatastoreSpec ( _config ) {
394
+ const spec = Object . assign ( { } , defaultDatastore . Spec , _get ( _config , 'datastore.Spec' , { } ) )
395
+
396
+ return {
397
+ type : spec . type ,
398
+ mounts : spec . mounts . map ( ( mounting ) => ( {
399
+ mountpoint : mounting . mountpoint ,
400
+ type : mounting . child . type ,
401
+ path : mounting . child . path ,
402
+ shardFunc : mounting . child . shardFunc
403
+ } ) )
404
+ }
405
+ }
0 commit comments