Mise à jour de GitLab prévue ce samedi 23 octobre 2021 à partir de 9h00 CET

Commit a5a2f0ca authored by Cédric Moreau's avatar Cédric Moreau
Browse files

Fix: could not start Duniter after fresh install

parent 9fec922c
......@@ -168,7 +168,7 @@ function CFSCore(rootPath, qfs, parent) {
}
}
} catch (e) {
if (e && e.code !== "EISDIR") throw e;
if (e && e.code !== "EISDIR" && e.code !== "EEXIST") throw e;
}
});
......
......@@ -2,10 +2,10 @@
var Q = require('q');
var co = require('co');
var _ = require('underscore');
var qfs = require('q-io/fs');
var path = require('path');
var hashf = require('../hashf');
var wotb = require('../wot');
var directory = require('../directory');
var Configuration = require('../entity/configuration');
var Membership = require('../entity/membership');
var Merkle = require('../entity/merkle');
......@@ -15,59 +15,21 @@ var ConfDAL = require('./fileDALs/confDAL');
var StatDAL = require('./fileDALs/statDAL');
var IndicatorsDAL = require('./fileDALs/IndicatorsDAL');
var CFSStorage = require('./fileDALs/AbstractCFS');
var sqlite3 = require("sqlite3b").verbose();
var logger = require('../../lib/logger')('database');
const UCOIN_DB_NAME = 'ucoin';
const WOTB_FILE = 'wotb.bin';
module.exports = {
memory: function(home) {
return getHomeFS(true, home)
.then(function(params) {
let sqlite = new sqlite3.Database(':memory:');
return Q(new FileDAL(params.home, "", params.fs, 'fileDal', sqlite, wotb.memoryInstance()));
});
},
file: function(home) {
return getHomeFS(false, home)
.then(function(params) {
let sqlitePath = path.join(params.home, UCOIN_DB_NAME + '.db');
let sqlite = new sqlite3.Database(sqlitePath);
return new FileDAL(params.home, "", params.fs, 'fileDal', sqlite, wotb.fileInstance(path.join(params.home, WOTB_FILE)));
});
},
FileDAL: FileDAL
};
function someDelayFix() {
return Q.Promise(function(resolve){
setTimeout(resolve, 100);
});
}
function getHomeFS(isMemory, home) {
let myfs;
return someDelayFix()
.then(function() {
myfs = (isMemory ? require('q-io/fs-mock')({}) : qfs);
return myfs.makeTree(home);
})
.then(function(){
return { fs: myfs, home: home };
});
}
function FileDAL(home, localDir, myFS, dalName, sqlite, wotbInstance) {
module.exports = (params) => {
return new FileDAL(params);
};
var that = this;
function FileDAL(params) {
let localHome = path.join(home, localDir);
let rootPath = params.home;
let myFS = params.fs;
let sqlite = params.db;
let wotbInstance = params.wotb;
let that = this;
this.name = dalName;
this.profile = 'DAL';
this.wotb = wotbInstance;
var rootPath = home;
// DALs
this.confDAL = new ConfDAL(rootPath, myFS, null, that, CFSStorage);
......@@ -121,12 +83,6 @@ function FileDAL(home, localDir, myFS, dalName, sqlite, wotbInstance) {
return currency;
};
this.removeHome = function() {
return myFS.removeTree(localHome)
.catch(function(){
});
};
that.writeFileOfBlock = function(block) {
return that.blockDAL.saveBlock(block);
};
......@@ -201,7 +157,7 @@ function FileDAL(home, localDir, myFS, dalName, sqlite, wotbInstance) {
else return block;
})
.catch(function(){
throw 'Block ' + [number, hash].join('-') + ' not found in ' + that.name;
throw 'Block ' + [number, hash].join('-') + ' not found';
})
.then(function(block){
done && done(null, block);
......@@ -1165,13 +1121,13 @@ function FileDAL(home, localDir, myFS, dalName, sqlite, wotbInstance) {
});
this.resetAll = function(done) {
var files = ['stats', 'cores', 'current', 'conf', UCOIN_DB_NAME, UCOIN_DB_NAME + '.db', WOTB_FILE];
var files = ['stats', 'cores', 'current', 'conf', directory.UCOIN_DB_NAME, directory.UCOIN_DB_NAME + '.db', directory.WOTB_FILE];
var dirs = ['blocks', 'ud_history', 'branches', 'certs', 'txs', 'cores', 'sources', 'links', 'ms', 'identities', 'peers', 'indicators', 'leveldb'];
return resetFiles(files, dirs, done);
};
this.resetData = function(done) {
var files = ['stats', 'cores', 'current', UCOIN_DB_NAME, UCOIN_DB_NAME + '.db', WOTB_FILE];
var files = ['stats', 'cores', 'current', directory.UCOIN_DB_NAME, directory.UCOIN_DB_NAME + '.db', directory.WOTB_FILE];
var dirs = ['blocks', 'ud_history', 'branches', 'certs', 'txs', 'cores', 'sources', 'links', 'ms', 'identities', 'peers', 'indicators', 'leveldb'];
return resetFiles(files, dirs, done);
};
......
......@@ -12,6 +12,4 @@ function AbstractCFS(rootPath, qioFS, parentDAL, localDAL) {
this.coreFS = cfs(rootPath, qioFS, parentDAL);
this.dal = localDAL;
this.changeParentCore = (newParent) => this.coreFS.changeParent(newParent);
}
\ No newline at end of file
}
"use strict";
var co = require('co');
var opts = require('optimist').argv;
var path = require('path');
var cfs = require('./cfs');
var Q = require('q');
var qfs = require('q-io/fs');
var sqlite3 = require("sqlite3b").verbose();
const DEFAULT_DOMAIN = "ucoin_default";
const DEFAULT_HOME = (process.platform == 'win32' ? process.env.USERPROFILE : process.env.HOME) + '/.config/ucoin/';
module.exports = {
let dir = module.exports = {
INSTANCE_NAME: getDomain(opts.mdb),
INSTANCE_HOME: getHomePath(opts.mdb, opts.home),
INSTANCE_HOMELOG_FILE: getLogsPath(opts.mdb, opts.home),
UCOIN_DB_NAME: 'ucoin',
WOTB_FILE: 'wotb.bin',
getHome: (profile, dir) => getHomePath(profile, dir)
getHome: (profile, dir) => getHomePath(profile, dir),
getHomeFS: (isMemory, theHome) => co(function *() {
let home = theHome || dir.getHome();
yield someDelayFix();
let params = {
home: home
};
if (isMemory) {
params.fs = require('q-io/fs-mock')({});
} else {
params.fs = qfs;
}
yield params.fs.makeTree(home);
return params;
}),
getHomeParams: (isMemory, theHome) => co(function *() {
let params = yield dir.getHomeFS(isMemory, theHome);
let home = params.home;
yield someDelayFix();
if (isMemory) {
params.db = new sqlite3.Database(':memory:');
params.wotb = require('./wot').memoryInstance();
} else {
let sqlitePath = path.join(home, dir.UCOIN_DB_NAME + '.db');
params.db = new sqlite3.Database(sqlitePath);
params.wotb = require('./wot').fileInstance(path.join(home, dir.WOTB_FILE));
}
return params;
}),
createHomeIfNotExists: (fs, theHome) => co(function *() {
let fsHandler = cfs(theHome, fs);
return fsHandler.makeTree('');
})
};
function someDelayFix() {
return Q.Promise(function(resolve){
setTimeout(resolve, 100);
});
}
function getLogsPath(profile, dir) {
return path.join(getHomePath(profile, dir), 'ucoin.log');
}
......
#!/usr/bin/env node
"use strict";
var logger = require('../app/lib/logger')('ucoind');
process.on('uncaughtException', function (err) {
// Dunno why this specific exception is not caught
if (err.code !== "EADDRNOTAVAIL") {
......@@ -9,7 +11,6 @@ process.on('uncaughtException', function (err) {
}
});
var logger = require('../app/lib/logger')('ucoind');
var async = require('async');
var co = require('co');
var Q = require('q');
......@@ -785,15 +786,19 @@ program
});
function webStart() {
var dbName = program.mdb;
var dbHome = program.home;
// Add log files for this instance
logger.addHomeLogs(directory.getHome(dbName, dbHome));
return co(function *() {
var dbName = program.mdb;
var dbHome = program.home;
if (!program.memory) {
let params = yield directory.getHomeFS(program.memory, dbHome);
yield directory.createHomeIfNotExists(params.fs, params.home);
co(function *() {
// Add log files for this instance
logger.addHomeLogs(params.home);
}
let webminapi = yield ucoin.statics.enableHttpAdmin({ home: dbHome, name: dbName, memory: program.memory }, commandLineConf(), false);
webminapi.openConnections();
return webminapi.openConnections();
});
}
......@@ -802,5 +807,12 @@ program.parse(process.argv);
if (program.args.length == 0) {
console.log('No command given, using default: ucoind webstart');
webStart();
};
return co(function *() {
try {
yield webStart();
} catch (e) {
logger.error(e);
process.exit();
}
});
}
......@@ -53,8 +53,8 @@ function Server (dbConf, overrideConf) {
this.plugFileSystem = () => co(function *() {
logger.debug('Plugging file system...');
var dbType = dbConf && dbConf.memory ? fileDAL.memory : fileDAL.file;
that.dal = yield dbType(home);
var params = yield directory.getHomeParams(dbConf && dbConf.memory, home);
that.dal = fileDAL(params);
});
this.unPlugFileSystem = () => co(function *() {
......
......@@ -4,6 +4,7 @@ var _ = require('underscore');
var should = require('should');
var assert = require('assert');
var dal = require('../../app/lib/dal/fileDAL');
var dir = require('../../app/lib/directory');
var constants = require('../../app/lib/constants');
var Peer = require('../../app/lib/entity/peer');
......@@ -162,16 +163,12 @@ var fileDAL = null;
describe("DAL", function(){
before(function() {
return dal.memory('db0')
.then(function(dal){
fileDAL = dal;
return dal.init();
})
.then(function() {
return fileDAL.saveConf({ currency: "meta_brouzouf" });
});
});
before(() => co(function *() {
let params = yield dir.getHomeParams(true, 'db0');
fileDAL = dal(params);
yield fileDAL.init();
return fileDAL.saveConf({ currency: "meta_brouzouf" });
}));
it('should have no peer in a first time', function(){
return fileDAL.listAllPeers().then(function(peers){
......@@ -189,7 +186,7 @@ describe("DAL", function(){
peers[0].should.have.property('currency').equal('bb');
peers[0].should.have.property('endpoints').length(1);
peers[0].endpoints[0].should.equal('BASIC_MERKLED_API localhost 7777');
});
});
});
it('should have no current block', function(){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment