directory structure.
This commit is contained in:
parent
1c2e1b8000
commit
1011d1f824
@ -208,14 +208,14 @@ Environment.prototype.set = function set(options) {
|
|||||||
|
|
||||||
options = utils.merge({}, options);
|
options = utils.merge({}, options);
|
||||||
|
|
||||||
options.prefix = options.prefix
|
|
||||||
|| process.env.BCOIN_PREFIX
|
|
||||||
|| utils.HOME + '/.bcoin';
|
|
||||||
|
|
||||||
options.network = options.network
|
options.network = options.network
|
||||||
|| process.env.BCOIN_NETWORK
|
|| process.env.BCOIN_NETWORK
|
||||||
|| 'main';
|
|| 'main';
|
||||||
|
|
||||||
|
options.prefix = options.prefix
|
||||||
|
|| process.env.BCOIN_PREFIX
|
||||||
|
|| utils.HOME + '/.bcoin/' + options.network;
|
||||||
|
|
||||||
if (!options.db)
|
if (!options.db)
|
||||||
options.db = process.env.BCOIN_DB;
|
options.db = process.env.BCOIN_DB;
|
||||||
|
|
||||||
@ -244,7 +244,7 @@ Environment.prototype.set = function set(options) {
|
|||||||
options.workerTimeout = +process.env.BCOIN_WORKER_TIMEOUT;
|
options.workerTimeout = +process.env.BCOIN_WORKER_TIMEOUT;
|
||||||
|
|
||||||
if (options.debugFile && typeof options.debugFile !== 'string')
|
if (options.debugFile && typeof options.debugFile !== 'string')
|
||||||
options.debugFile = options.prefix + '/debug-' + options.network + '.log';
|
options.debugFile = options.prefix + '/debug.log';
|
||||||
|
|
||||||
this.prefix = options.prefix;
|
this.prefix = options.prefix;
|
||||||
this.networkType = options.network;
|
this.networkType = options.network;
|
||||||
@ -284,14 +284,7 @@ Environment.prototype.ensurePrefix = function ensurePrefix() {
|
|||||||
|
|
||||||
this._ensured = true;
|
this._ensured = true;
|
||||||
|
|
||||||
try {
|
mkdirp(this.prefix);
|
||||||
fs.statSync(this.prefix);
|
|
||||||
} catch (e) {
|
|
||||||
if (e.code === 'ENOENT')
|
|
||||||
fs.mkdirSync(this.prefix, 488 /* 0750 */);
|
|
||||||
else
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -376,7 +369,7 @@ Environment.prototype.write = function write(msg) {
|
|||||||
this._debug = fs.createWriteStream(this.debugFile, { flags: 'a' });
|
this._debug = fs.createWriteStream(this.debugFile, { flags: 'a' });
|
||||||
}
|
}
|
||||||
|
|
||||||
this._debug.write(process.pid + ': ' + msg + '\n');
|
this._debug.write(process.pid + ' (' + utils.date() + '): ' + msg + '\n');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -388,6 +381,47 @@ Environment.prototype.now = function now() {
|
|||||||
return this.time.now();
|
return this.time.now();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a full directory structure.
|
||||||
|
* @param {String} dir
|
||||||
|
*/
|
||||||
|
|
||||||
|
function mkdirp(dir) {
|
||||||
|
var path = require('path');
|
||||||
|
var i, parts, name;
|
||||||
|
|
||||||
|
if (!fs)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dir = path.normalize(dir);
|
||||||
|
dir = dir.replace(/\\/g, '/');
|
||||||
|
dir = dir.replace(/\/$/, '');
|
||||||
|
parts = dir.split('/');
|
||||||
|
|
||||||
|
for (i = 0; i < parts.length; i++) {
|
||||||
|
if (i === 0) {
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
if (parts[0].indexOf(':') !== -1)
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
if (parts[0].length === 0)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
name = parts.slice(0, i + 1).join('/');
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.statSync(name);
|
||||||
|
} catch (e) {
|
||||||
|
if (e.code === 'ENOENT')
|
||||||
|
fs.mkdirSync(name, 488 /* 0750 */);
|
||||||
|
else
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Expose by converting `exports` to an
|
* Expose by converting `exports` to an
|
||||||
* Environment.
|
* Environment.
|
||||||
|
|||||||
@ -117,13 +117,7 @@ ldb.getLocation = function getLocation(options) {
|
|||||||
if (options.location)
|
if (options.location)
|
||||||
return options.location;
|
return options.location;
|
||||||
|
|
||||||
return bcoin.prefix
|
return bcoin.prefix + '/' + options.name + '.' + backend.ext;
|
||||||
+ '/'
|
|
||||||
+ options.name
|
|
||||||
+ '-'
|
|
||||||
+ bcoin.network.get(options.network).type
|
|
||||||
+ '.'
|
|
||||||
+ backend.ext;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user