Рефакторинг
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const fs = require('fs');
|
||||
const fs = require('fs-extra');
|
||||
const utils = require('../core/utils');
|
||||
|
||||
const branchFilename = __dirname + '/application_env';
|
||||
@@ -18,6 +18,6 @@ fs.accessSync(confFilename);
|
||||
|
||||
const config = require(confFilename);
|
||||
|
||||
utils.mkDirIfNotExistsSync(config.dataDir);
|
||||
//fs.ensureDirSync(config.dataDir);
|
||||
|
||||
module.exports = config;
|
||||
@@ -1,9 +1,7 @@
|
||||
/*
|
||||
Журналирование с буферизацией вывода
|
||||
*/
|
||||
|
||||
const Promise = require('bluebird');
|
||||
const fs = Promise.promisifyAll(require('fs'));
|
||||
const fs = require('fs-extra');
|
||||
|
||||
global.LM_OK = 0;
|
||||
global.LM_INFO = 1;
|
||||
@@ -120,25 +118,25 @@ class FileLog extends BaseLog {
|
||||
if (i > 0)
|
||||
fn += `.${i}`;
|
||||
let tn = fileName + '.' + (i + 1);
|
||||
let exists = await fs.accessAsync(tn).then(() => true).catch(() => false);
|
||||
let exists = await fs.access(tn).then(() => true).catch(() => false);
|
||||
if (exists) {
|
||||
if (i >= LOG_ROTATE_FILE_DEPTH - 1) {
|
||||
await fs.unlinkAsync(tn);
|
||||
await fs.unlink(tn);
|
||||
} else {
|
||||
await this.rotateFile(fileName, i + 1);
|
||||
}
|
||||
}
|
||||
await fs.renameAsync(fn, tn);
|
||||
await fs.rename(fn, tn);
|
||||
}
|
||||
|
||||
async doFileRotationIfNeeded() {
|
||||
this.rcid = 0;
|
||||
|
||||
let stat = await fs.fstatAsync(this.fd);
|
||||
let stat = await fs.fstat(this.fd);
|
||||
if (stat.size > LOG_ROTATE_FILE_LENGTH) {
|
||||
await fs.closeAsync(this.fd);
|
||||
await fs.close(this.fd);
|
||||
await this.rotateFile(this.fileName, 0);
|
||||
this.fd = await fs.openAsync(this.fileName, "a");
|
||||
this.fd = await fs.open(this.fileName, "a");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +151,7 @@ class FileLog extends BaseLog {
|
||||
}, LOG_ROTATE_FILE_CHECK_INTERVAL);
|
||||
};
|
||||
|
||||
await fs.writeAsync(this.fd, Buffer.from(data.join('')));
|
||||
await fs.write(this.fd, Buffer.from(data.join('')));
|
||||
}
|
||||
|
||||
flushImplSync(data) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const Promise = require('bluebird');
|
||||
const fs = require('fs-extra');
|
||||
const utils = require('./utils');
|
||||
const sqlite = require('sqlite');
|
||||
|
||||
@@ -11,7 +12,7 @@ class SqliteConnectionPool {
|
||||
}
|
||||
|
||||
async init() {
|
||||
utils.mkDirIfNotExistsSync(this.config.dataDir);
|
||||
fs.ensureDirSync(this.config.dataDir);
|
||||
const dbFileName = this.config.dataDir + '/' + this.config.dbFileName;
|
||||
|
||||
this.connections = [];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const utils = require('./utils');
|
||||
const fs = require('fs-extra');
|
||||
const Logger = require('./Logger');
|
||||
|
||||
let logger = null;
|
||||
@@ -10,7 +10,7 @@ function initLogger(config) {
|
||||
let loggerParams = null;
|
||||
|
||||
if (config.loggingEnabled) {
|
||||
utils.mkDirIfNotExistsSync(config.logDir);
|
||||
fs.ensureDirSync(config.logDir);
|
||||
loggerParams = [
|
||||
{log: 'ConsoleLog'},
|
||||
{log: 'FileLog', fileName: `${config.logDir}/${config.name}.log`},
|
||||
|
||||
@@ -1,28 +1,9 @@
|
||||
const Promise = require('bluebird');
|
||||
const fs = require('fs');
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
function statPathSync(path) {
|
||||
try {
|
||||
return fs.statSync(path);
|
||||
} catch (ex) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
function mkDirIfNotExistsSync(path) {
|
||||
let exists = statPathSync(path);
|
||||
if (!exists) {
|
||||
fs.mkdirSync(path, {recursive: true});
|
||||
} else if (!exists.isDirectory()) {
|
||||
throw new Error(`Not a directory: ${path}`);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
sleep,
|
||||
statPathSync,
|
||||
mkDirIfNotExistsSync,
|
||||
sleep
|
||||
};
|
||||
Reference in New Issue
Block a user