From a33774aa6f7184f7144e9f2fa6e42af32b391025 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 10 Aug 2021 15:24:23 +0530 Subject: [PATCH] properly abort from channel archival if no metadata is returned and add some logging when trimming history --- lib/commands/channel.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/commands/channel.js b/lib/commands/channel.js index e69f93180..c36c3424d 100644 --- a/lib/commands/channel.js +++ b/lib/commands/channel.js @@ -54,7 +54,8 @@ Channel.clearOwnedChannel = function (Env, safeKey, channelId, cb, Server) { }); }; -var archiveOwnedChannel = function (Env, safeKey, channelId, _cb, Server) { +var archiveOwnedChannel = function (Env, safeKey, channelId, __cb, Server) { + var _cb = Util.once(Util.mkAsync(__cb)); var unsafeKey = Util.unescapeKeyCharacters(safeKey); nThen(function (w) { // confirm that the channel exists before worrying about whether @@ -160,7 +161,10 @@ Channel.trimHistory = function (Env, safeKey, data, cb) { nThen(function (w) { Metadata.getMetadataRaw(Env, channelId, w(function (err, metadata) { - if (err) { return void cb(err); } + if (err) { + w.abort(); + return void cb(err); + } if (!Core.hasOwners(metadata)) { w.abort(); return void cb('E_NO_OWNERS'); @@ -173,6 +177,11 @@ Channel.trimHistory = function (Env, safeKey, data, cb) { })); }).nThen(function () { Env.msgStore.trimChannel(channelId, hash, function (err) { + Env.Log.info('HK_TRIM_HISTORY', { + unsafeKey: unsafeKey, + channelId: channelId, + status: err? String(e): 'SUCCESS', + }); if (err) { return void cb(err); } // clear historyKeeper's cache for this channel Env.historyKeeper.channelClose(channelId);