diff --git a/bin/checkPadDeltas.js b/bin/checkPadDeltas.js new file mode 100644 index 000000000..830877f7b --- /dev/null +++ b/bin/checkPadDeltas.js @@ -0,0 +1,154 @@ +/* + This is a debug tool. It checks all revisions for data corruption +*/ + +if(process.argv.length != 3) +{ + console.error("Use: node bin/checkPad.js $PADID"); + process.exit(1); +} +//get the padID +var padId = process.argv[2]; + +//initalize the variables +var db, settings, padManager; +var npm = require("ep_etherpad-lite/node_modules/npm"); +var async = require("ep_etherpad-lite/node_modules/async"); + +var Changeset = require("ep_etherpad-lite/static/js/Changeset"); + +// external dependencies +var expect = require('expect.js') +var diff = require('diff') + +async.series([ + //load npm + function(callback) { + npm.load({}, function(er) { + callback(er); + }) + }, + //load modules + function(callback) { + settings = require('ep_etherpad-lite/node/utils/Settings'); + db = require('ep_etherpad-lite/node/db/DB'); + + //intallize the database + db.init(callback); + }, + //get the pad + function (callback) + { + padManager = require('ep_etherpad-lite/node/db/PadManager'); + + 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) + { + //check if the pad has a pool + if(pad.pool === undefined ) + { + console.error("Attribute pool is missing"); + process.exit(1); + } + + //check if the pad has atext + if(pad.atext === undefined ) + { + console.error("AText is missing"); + process.exit(1); + } + + + //create an array with key revisions + //key revisions always save the full pad atext + var head = pad.getHeadRevisionNumber(); + var keyRevisions = []; + for(var i=0;i