blockstore: add ensure method to create directories
This commit is contained in:
parent
0b0dd58a91
commit
89d3253f29
@ -30,6 +30,16 @@ class AbstractBlockStore {
|
|||||||
this.logger = Logger.global.context('blockstore');
|
this.logger = Logger.global.context('blockstore');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method ensures that resources are available
|
||||||
|
* before opening.
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
|
||||||
|
async ensure() {
|
||||||
|
throw new Error('Abstract method.');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method opens any necessary resources and
|
* This method opens any necessary resources and
|
||||||
* initializes the store to be ready to be queried.
|
* initializes the store to be ready to be queried.
|
||||||
|
|||||||
@ -129,6 +129,17 @@ class FileBlockStore extends AbstractBlockStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method ensures that both the block storage directory
|
||||||
|
* and index directory exist.
|
||||||
|
* before opening.
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
|
||||||
|
async ensure() {
|
||||||
|
return fs.mkdirp(this.indexLocation);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the file block store. It will regenerate necessary block
|
* Opens the file block store. It will regenerate necessary block
|
||||||
* indexing if the index is missing or inconsistent.
|
* indexing if the index is missing or inconsistent.
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const bdb = require('bdb');
|
const bdb = require('bdb');
|
||||||
|
const fs = require('bfile');
|
||||||
const AbstractBlockStore = require('./abstract');
|
const AbstractBlockStore = require('./abstract');
|
||||||
const layout = require('./layout');
|
const layout = require('./layout');
|
||||||
const {types} = require('./common');
|
const {types} = require('./common');
|
||||||
@ -37,6 +38,16 @@ class LevelBlockStore extends AbstractBlockStore {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method ensures that the storage directory exists
|
||||||
|
* before opening.
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
|
||||||
|
async ensure() {
|
||||||
|
return fs.mkdirp(this.location);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the block storage.
|
* Opens the block storage.
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
|
|||||||
@ -57,6 +57,7 @@ class Node extends EventEmitter {
|
|||||||
this.workers = null;
|
this.workers = null;
|
||||||
|
|
||||||
this.spv = false;
|
this.spv = false;
|
||||||
|
this.blocks = null;
|
||||||
this.chain = null;
|
this.chain = null;
|
||||||
this.fees = null;
|
this.fees = null;
|
||||||
this.mempool = null;
|
this.mempool = null;
|
||||||
@ -135,6 +136,9 @@ class Node extends EventEmitter {
|
|||||||
if (this.memory)
|
if (this.memory)
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
||||||
|
if (this.blocks)
|
||||||
|
await this.blocks.ensure();
|
||||||
|
|
||||||
return fs.mkdirp(this.config.prefix);
|
return fs.mkdirp(this.config.prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,6 @@ const common = require('./util/common');
|
|||||||
const {resolve} = require('path');
|
const {resolve} = require('path');
|
||||||
const fs = require('bfile');
|
const fs = require('bfile');
|
||||||
const {rimraf} = require('./util/common');
|
const {rimraf} = require('./util/common');
|
||||||
const {mkdirp} = require('bfile');
|
|
||||||
const random = require('bcrypto/lib/random');
|
const random = require('bcrypto/lib/random');
|
||||||
|
|
||||||
const vectors = [
|
const vectors = [
|
||||||
@ -347,13 +346,13 @@ describe('BlockStore', function() {
|
|||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await rimraf(location);
|
await rimraf(location);
|
||||||
await mkdirp(location);
|
|
||||||
|
|
||||||
store = new FileBlockStore({
|
store = new FileBlockStore({
|
||||||
location: location,
|
location: location,
|
||||||
maxFileLength: 1024
|
maxFileLength: 1024
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await store.ensure();
|
||||||
await store.open();
|
await store.open();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -657,13 +656,13 @@ describe('BlockStore', function() {
|
|||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await rimraf(location);
|
await rimraf(location);
|
||||||
await mkdirp(location);
|
|
||||||
|
|
||||||
store = new FileBlockStore({
|
store = new FileBlockStore({
|
||||||
location: location,
|
location: location,
|
||||||
maxFileLength: 1024 * 1024
|
maxFileLength: 1024 * 1024
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await store.ensure();
|
||||||
await store.open();
|
await store.open();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -709,12 +708,12 @@ describe('BlockStore', function() {
|
|||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await rimraf(location);
|
await rimraf(location);
|
||||||
await mkdirp(location);
|
|
||||||
|
|
||||||
store = new LevelBlockStore({
|
store = new LevelBlockStore({
|
||||||
location: location
|
location: location
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await store.ensure();
|
||||||
await store.open();
|
await store.open();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user