2011-12-05 17:24:59 +00:00
|
|
|
/*
|
|
|
|
This is a debug tool. It checks all revisions for data corruption
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(process.argv.length != 3)
|
|
|
|
{
|
2012-04-30 17:23:41 +00:00
|
|
|
console.error("Use: node bin/checkPad.js $PADID");
|
2011-12-05 17:24:59 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
//get the padID
|
|
|
|
var padId = process.argv[2];
|
|
|
|
|
2017-09-14 11:33:27 +00:00
|
|
|
//initialize the variables
|
2013-01-15 06:31:51 +00:00
|
|
|
var db, settings, padManager;
|
|
|
|
var npm = require("../src/node_modules/npm");
|
2012-04-30 17:23:41 +00:00
|
|
|
var async = require("../src/node_modules/async");
|
2012-02-28 20:19:10 +00:00
|
|
|
|
2012-02-26 16:48:17 +00:00
|
|
|
var Changeset = require("ep_etherpad-lite/static/js/Changeset");
|
2011-12-05 17:24:59 +00:00
|
|
|
|
|
|
|
async.series([
|
2013-01-15 06:31:51 +00:00
|
|
|
//load npm
|
|
|
|
function(callback) {
|
|
|
|
npm.load({}, function(er) {
|
|
|
|
callback(er);
|
|
|
|
})
|
|
|
|
},
|
|
|
|
//load modules
|
|
|
|
function(callback) {
|
|
|
|
settings = require('../src/node/utils/Settings');
|
|
|
|
db = require('../src/node/db/DB');
|
2013-01-17 16:31:56 +00:00
|
|
|
|
2017-09-14 11:33:27 +00:00
|
|
|
//initialize the database
|
2011-12-05 17:24:59 +00:00
|
|
|
db.init(callback);
|
|
|
|
},
|
|
|
|
//get the pad
|
|
|
|
function (callback)
|
|
|
|
{
|
2012-04-30 17:23:41 +00:00
|
|
|
padManager = require('../src/node/db/PadManager');
|
2011-12-05 17:24:59 +00:00
|
|
|
|
|
|
|
padManager.doesPadExists(padId, function(err, exists)
|
|
|
|
{
|
|
|
|
if(!exists)
|
|
|
|
{
|
|
|
|
console.error("Pad does not exist");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
padManager.getPad(padId, function(err, _pad)
|
|
|
|
{
|
|
|
|
pad = _pad;
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function (callback)
|
|
|
|
{
|
2017-09-14 11:33:27 +00:00
|
|
|
//create an array with key revisions
|
2011-12-05 17:24:59 +00:00
|
|
|
//key revisions always save the full pad atext
|
|
|
|
var head = pad.getHeadRevisionNumber();
|
|
|
|
var keyRevisions = [];
|
|
|
|
for(var i=0;i<head;i+=100)
|
|
|
|
{
|
|
|
|
keyRevisions.push(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
//run trough all key revisions
|
|
|
|
async.forEachSeries(keyRevisions, function(keyRev, callback)
|
|
|
|
{
|
|
|
|
//create an array of revisions we need till the next keyRevision or the End
|
|
|
|
var revisionsNeeded = [];
|
|
|
|
for(var i=keyRev;i<=keyRev+100 && i<=head; i++)
|
|
|
|
{
|
|
|
|
revisionsNeeded.push(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
//this array will hold all revision changesets
|
|
|
|
var revisions = [];
|
|
|
|
|
|
|
|
//run trough all needed revisions and get them from the database
|
|
|
|
async.forEach(revisionsNeeded, function(revNum, callback)
|
|
|
|
{
|
|
|
|
db.db.get("pad:"+padId+":revs:" + revNum, function(err, revision)
|
|
|
|
{
|
|
|
|
revisions[revNum] = revision;
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
}, function(err)
|
|
|
|
{
|
|
|
|
if(err)
|
|
|
|
{
|
|
|
|
callback(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//check if the pad has a pool
|
|
|
|
if(pad.pool === undefined )
|
|
|
|
{
|
|
|
|
console.error("Attribute pool is missing");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2017-09-14 11:33:27 +00:00
|
|
|
//check if there is an atext in the keyRevisions
|
2011-12-05 17:24:59 +00:00
|
|
|
if(revisions[keyRev] === undefined || revisions[keyRev].meta === undefined || revisions[keyRev].meta.atext === undefined)
|
|
|
|
{
|
|
|
|
console.error("No atext in key revision " + keyRev);
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var apool = pad.pool;
|
|
|
|
var atext = revisions[keyRev].meta.atext;
|
|
|
|
|
|
|
|
for(var i=keyRev+1;i<=keyRev+100 && i<=head; i++)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
//console.log("check revision " + i);
|
|
|
|
var cs = revisions[i].changeset;
|
|
|
|
atext = Changeset.applyToAText(cs, atext, apool);
|
|
|
|
}
|
|
|
|
catch(e)
|
|
|
|
{
|
|
|
|
console.error("Bad changeset at revision " + i + " - " + e.message);
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}, callback);
|
|
|
|
}
|
|
|
|
], function (err)
|
|
|
|
{
|
|
|
|
if(err) throw err;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.log("finished");
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
});
|