]> git.sesse.net Git - remoteglot/blobdiff - server/serve-analysis.js
Verify that JSON_delta does not have any strangeness.
[remoteglot] / server / serve-analysis.js
index de884a3439f68ade5b11b4a16255cb07bd9895ab..41610e1439d733d2f73c0389351f711454a5e9a0 100644 (file)
@@ -132,8 +132,19 @@ var create_json_historic_diff = function(new_json, history_left, new_diff_json,
        }
 
        var histobj = history_left.shift();
-       var diff = delta.JSON_delta.diff(histobj.parsed, new_json.parsed, false);
+       var diff = delta.JSON_delta.diff(histobj.parsed, new_json.parsed);
        var diff_text = JSON.stringify(diff);
+
+       // Verify that the delta is correct
+       var base = JSON.parse(histobj.plain);
+       delta.JSON_delta.patch(base, diff);
+       var correct_pv = JSON.stringify(base['pv']);
+       var wrong_pv = JSON.stringify(new_json.parsed['pv']);
+       if (correct_pv !== wrong_pv) {
+               console.log("Patch went wrong:", histobj.plain, new_json.plain);
+               exit();
+       }
+
        zlib.gzip(diff_text, function(err, buffer) {
                if (err) throw err;
                new_diff_json[histobj.last_modified] = {
@@ -183,7 +194,7 @@ var reread_file = function(event, filename) {
        touch_timer = setTimeout(function() {
                console.log("Touching analysis.json due to no other activity");
                var now = Date.now() / 1000;
-               fs.utimes(json_filename, now, now);
+               fs.utimes(json_filename, now, now, function() {});
        }, 30000);
 }
 var possibly_wakeup_clients = function() {