From 95778cc7c944d656118ce5912e9ececed3f5239e Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 23 Jul 2020 09:30:04 -0400 Subject: [PATCH] respond with ENOENT instead of E_NO_OWNERS when archiving a file that does not exist --- lib/commands/channel.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/commands/channel.js b/lib/commands/channel.js index fce5b048c..46502d06e 100644 --- a/lib/commands/channel.js +++ b/lib/commands/channel.js @@ -54,14 +54,29 @@ 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 unsafeKey = Util.unescapeKeyCharacters(safeKey); - Metadata.getMetadata(Env, channelId, function (err, metadata) { - if (err) { return void cb(err); } - if (!Core.hasOwners(metadata)) { return void cb('E_NO_OWNERS'); } - if (!Core.isOwner(metadata, unsafeKey)) { - return void cb('INSUFFICIENT_PERMISSIONS'); - } + nThen(function (w) { + // confirm that the channel exists before worrying about whether + // we have permission to delete it. + var cb = _cb; + Env.msgStore.getChannelSize(channelId, w(function (err, bytes) { + if (!bytes) { + w.abort(); + return cb(err || "ENOENT"); + } + })); + }).nThen(function (w) { + var cb = Util.both(w.abort, _cb); + Metadata.getMetadata(Env, channelId, function (err, metadata) { + if (err) { return void cb(err); } + if (!Core.hasOwners(metadata)) { return void cb('E_NO_OWNERS'); } + if (!Core.isOwner(metadata, unsafeKey)) { + return void cb('INSUFFICIENT_PERMISSIONS'); + } + }); + }).nThen(function () { + var cb = _cb; // temporarily archive the file return void Env.msgStore.archiveChannel(channelId, function (e) { Env.Log.info('ARCHIVAL_CHANNEL_BY_OWNER_RPC', {