store: better handling moving messages

sort results (for testing)

with the ChangeName flag, also apply to dup messages.
This commit is contained in:
Dirk-Jan C. Binnema 2023-09-24 15:48:58 +03:00
parent 5d37c18d7d
commit b0dca49dc0
2 changed files with 12 additions and 6 deletions

View File

@ -548,7 +548,7 @@ Store::move_message(Store::Id id,
if (none_of(opts & Store::MoveOptions::DupFlags) || message_id.empty() || !new_flags)
return Ok(std::move(id_paths));
/* handle the dupflags case; i.e. apply (a subset of) the flags to
/* handle the dup-flags case; i.e. apply (a subset of) the flags to
* all messages with the same message-id as well */
auto dups{priv_->find_duplicates_unlocked(*this, message_id)};
for (auto&& dupid: dups) {
@ -562,17 +562,20 @@ Store::move_message(Store::Id id,
/* For now, don't change Draft/Flagged/Trashed */
const auto dup_flags{filter_dup_flags(dup_msg->flags(), *new_flags)};
/* use the updated new_flags and default MoveOptions (so we don't recurse, nor do we
* change the base-name of moved messages) */
/* use the updated new_flags and MoveOptions without DupFlags (so we don't
* recurse) */
opts = opts & ~MoveOptions::DupFlags;
if (auto dup_res = priv_->move_message_unlocked(
std::move(*dup_msg), Nothing,
dup_flags,
Store::MoveOptions::None); !dup_res)
std::move(*dup_msg), Nothing, dup_flags, opts); !dup_res)
mu_warning("failed to move dup: {}", dup_res.error().what());
else
id_paths.emplace_back(dupid, dup_res->first);
}
// sort the dup paths by name;
std::sort(id_paths.begin() + 1, id_paths.end(),
[](const auto& idp1, const auto& idp2) { return idp1.second < idp2.second; });
return Ok(std::move(id_paths));
}

View File

@ -309,6 +309,9 @@ public:
* @return Result, either an IdPathVec with ids and paths for the moved message(s) or some
* error. Note that in case of success at least one message is returned, and only with
* MoveOptions::DupFlags can it be more than one.
*
* The first element of the IdPathVec, is the main message that got move; any subsequent
* (if any) are the duplicate paths, sorted by path-name.
*/
Result<IdPathVec> move_message(Store::Id id,
Option<const std::string&> target_mdir = Nothing,