From ed09b92592d070bf4cfbd708dc6f299c682ad191 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 22 Mar 2021 10:39:41 +0100 Subject: [PATCH] Fix deleted pad restored corrupted from cache --- lib/hk-util.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/hk-util.js b/lib/hk-util.js index 8780addcd..0d8d6224f 100644 --- a/lib/hk-util.js +++ b/lib/hk-util.js @@ -661,6 +661,8 @@ const handleGetHistory = function (Env, Server, seq, userId, parsed) { if (txid) { msg[0] = txid; } Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId, JSON.stringify(msg)], readMore); }, (err) => { + // Any error but ENOENT: abort + // ENOENT is allowed in case we want to create a new pad if (err && err.code !== 'ENOENT') { if (err.message === "EUNKNOWN") { Log.error("HK_GET_HISTORY", { @@ -680,6 +682,14 @@ const handleGetHistory = function (Env, Server, seq, userId, parsed) { return; } + // If we're asking for a specific version (lastKnownHash) but we receive an + // ENOENT, this is not a pad creation so we need to abort. + if (err && err.code === 'ENOENT' && lastKnownHash) { + const parsedMsg2 = {error:'EDELETED', channel: channelName, txid: txid}; + Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId, JSON.stringify(parsedMsg2)]); + return; + } + if (msgCount === 0 && !metadata_cache[channelName] && Server.channelContainsUser(channelName, userId)) { handleFirstMessage(Env, channelName, metadata); Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId, JSON.stringify(metadata)]);