|  | 
| 1 | 1 | 'use strict' | 
| 2 | 2 | 
 | 
| 3 | 3 | const _get = require('just-safe-get') | 
| 4 |  | -const assert = require('assert') | 
| 5 |  | -const path = require('path') | 
| 6 | 4 | const debug = require('debug') | 
| 7 | 5 | const Big = require('bignumber.js') | 
| 8 | 6 | const errcode = require('err-code') | 
| 9 | 7 | const migrator = require('ipfs-repo-migrations') | 
| 10 | 8 | const bytes = require('bytes') | 
|  | 9 | +const pathJoin = require('ipfs-utils/src/path-join') | 
| 11 | 10 | 
 | 
| 12 | 11 | const constants = require('./constants') | 
| 13 | 12 | const backends = require('./backends') | 
| @@ -40,7 +39,9 @@ class IpfsRepo { | 
| 40 | 39 |    * @param {object} options - Configuration | 
| 41 | 40 |    */ | 
| 42 | 41 |   constructor (repoPath, options) { | 
| 43 |  | -    assert.strictEqual(typeof repoPath, 'string', 'missing repoPath') | 
|  | 42 | +    if (typeof repoPath !== 'string') { | 
|  | 43 | +      throw new Error('missing repoPath') | 
|  | 44 | +    } | 
| 44 | 45 | 
 | 
| 45 | 46 |     this.options = buildOptions(options) | 
| 46 | 47 |     this.closed = true | 
| @@ -112,13 +113,15 @@ class IpfsRepo { | 
| 112 | 113 |       this.lockfile = await this._openLock(this.path) | 
| 113 | 114 |       log('acquired repo.lock') | 
| 114 | 115 |       log('creating datastore') | 
| 115 |  | -      this.datastore = backends.create('datastore', path.join(this.path, 'datastore'), this.options) | 
|  | 116 | +      this.datastore = backends.create('datastore', pathJoin(this.path, 'datastore'), this.options) | 
|  | 117 | +      await this.datastore.open() | 
| 116 | 118 |       log('creating blocks') | 
| 117 |  | -      const blocksBaseStore = backends.create('blocks', path.join(this.path, 'blocks'), this.options) | 
|  | 119 | +      const blocksBaseStore = backends.create('blocks', pathJoin(this.path, 'blocks'), this.options) | 
|  | 120 | +      await blocksBaseStore.open() | 
| 118 | 121 |       this.blocks = await blockstore(blocksBaseStore, this.options.storageBackendOptions.blocks) | 
| 119 | 122 |       log('creating keystore') | 
| 120 |  | -      this.keys = backends.create('keys', path.join(this.path, 'keys'), this.options) | 
| 121 |  | - | 
|  | 123 | +      this.keys = backends.create('keys', pathJoin(this.path, 'keys'), this.options) | 
|  | 124 | +      await this.keys.open() | 
| 122 | 125 |       const isCompatible = await this.version.check(constants.repoVersion) | 
| 123 | 126 |       if (!isCompatible) { | 
| 124 | 127 |         if (await this._isAutoMigrationEnabled()) { | 
| @@ -152,11 +155,15 @@ class IpfsRepo { | 
| 152 | 155 |    */ | 
| 153 | 156 |   _getLocker () { | 
| 154 | 157 |     if (typeof this.options.lock === 'string') { | 
| 155 |  | -      assert(lockers[this.options.lock], 'Unknown lock type: ' + this.options.lock) | 
|  | 158 | +      if (!lockers[this.options.lock]) { | 
|  | 159 | +        throw new Error('Unknown lock type: ' + this.options.lock) | 
|  | 160 | +      } | 
| 156 | 161 |       return lockers[this.options.lock] | 
| 157 | 162 |     } | 
| 158 | 163 | 
 | 
| 159 |  | -    assert(this.options.lock, 'No lock provided') | 
|  | 164 | +    if (!this.options.lock) { | 
|  | 165 | +      throw new Error('No lock provided') | 
|  | 166 | +    } | 
| 160 | 167 |     return this.options.lock | 
| 161 | 168 |   } | 
| 162 | 169 | 
 | 
| @@ -251,7 +258,13 @@ class IpfsRepo { | 
| 251 | 258 |       } | 
| 252 | 259 |     } | 
| 253 | 260 | 
 | 
| 254 |  | -    await Promise.all([this.root, this.blocks, this.keys, this.datastore].map((store) => store.close())) | 
|  | 261 | +    await Promise.all([ | 
|  | 262 | +      this.root, | 
|  | 263 | +      this.blocks, | 
|  | 264 | +      this.keys, | 
|  | 265 | +      this.datastore | 
|  | 266 | +    ].map((store) => store.close())) | 
|  | 267 | + | 
| 255 | 268 |     log('unlocking') | 
| 256 | 269 |     this.closed = true | 
| 257 | 270 |     await this._closeLock() | 
|  | 
0 commit comments