From c75a75b243ea4e2892e8e1e007fca6905e19d0ba Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 30 Nov 2022 14:39:38 +0100 Subject: [PATCH] Don't search for an old hash in a file when a cache is deprecated --- lib/hk-util.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/hk-util.js b/lib/hk-util.js index a95eb19a6..5fd5d2158 100644 --- a/lib/hk-util.js +++ b/lib/hk-util.js @@ -428,6 +428,7 @@ const getHistoryOffset = (Env, channelName, lastKnownHash, _cb) => { // lastKnownhash === -1 means we want the complete history if (lastKnownHash === -1) { return void cb(null, 0); } + let offset = -1; nThen((waitFor) => { getIndex(Env, channelName, waitFor((err, index) => { @@ -436,8 +437,11 @@ const getHistoryOffset = (Env, channelName, lastKnownHash, _cb) => { // check if the "hash" the client is requesting exists in the index const lkh = index.offsetByHash[lastKnownHash]; - // fall through to the next block if the offset of the hash in question is not in memory - if (lastKnownHash && typeof(lkh) !== "number") { return; } + // Hash too old or no longer exists, empty cache + if (lastKnownHash && typeof(lkh) !== "number") { + waitFor.abort(); + return void cb(new Error('EUNKNOWN')); + } // If we have a lastKnownHash or we didn't ask for one, we don't need the next blocks waitFor.abort(); @@ -477,6 +481,9 @@ const getHistoryOffset = (Env, channelName, lastKnownHash, _cb) => { cb(null, lkh); })); }).nThen((w) => { + // XXX entire block and getHashOffset to remove? + + // skip past this block if the offset is anything other than -1 // this basically makes these first two nThen blocks behave like if-else if (offset !== -1) { return; }