Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
db.close(function(err){
if(err) throw err;
console.log('Destroying current DB.');
levelup.destroy('./'+id+'.db',function(err){
if(err) throw err;
console.log('Creating new DB.');
db=levelup('./'+id+'.db');
db.batch(data, function (err) {
console.log('Installing data...');
if(err) throw err;
installSnapshot.pendingBatches--;
if(done){
var message=JSON.stringify({rpc: 'replyAppendEntries', term: currentTerm, followerId: id, entriesToAppend: 0, success: true});
log=newLog();
log.shift();
log.firstIndex=lastIncludedIndex+1;
log.length=log.firstIndex;
commitIndex=lastIncludedIndex;
lastApplied=lastIncludedIndex;
recoveryMode=false;
db.get('~meta~', function (err, value) {
if(value)
try { value = JSON.parse(value) }
catch (err) { return cb(null, 0) }
if(err) //first time this was run
cb(null, 0)
//if the view has changed, rebuild entire index.
//else, read current version.
else if(version && value.version !== version)
level.destroy(path, function (err) {
if(err) return cb(err)
db = level(path)
cb(null, 0)
})
else
cb(null, value.since || 0)
})
},
.then(exists => (exists ? level.destroy(baseDir + sep + table).then(() => fs.remove(baseDir + sep + table)) : null));
function destroy () {
db.close()
level.destroy(path)
}
close(function () {
Level.destroy(path, function (err) {
if(err) throw err //just die?
db = create(path)
since = 0
next()
})
})
}