From fe6582c6d6d5e4378f0a4641b2d2516a1d01f7af Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 10 Jun 2020 09:04:47 +0300 Subject: [PATCH] lib: implement mu_store_update --- lib/mu-store.cc | 19 ++++++++++++++++++- lib/mu-store.hh | 10 ++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/mu-store.cc b/lib/mu-store.cc index 7ceaa966..1c02fab9 100644 --- a/lib/mu-store.cc +++ b/lib/mu-store.cc @@ -343,12 +343,29 @@ Store::add_message (const std::string& path) const auto docid{add_or_update_msg (store, 0, msg, &gerr)}; mu_msg_unref (msg); if (G_UNLIKELY(docid == MU_STORE_INVALID_DOCID)) - throw Error{Error::Code::Message, "failed to store message: %s", + throw Error{Error::Code::Message, "failed to add message: %s", gerr ? gerr->message : "something went wrong"}; return docid; } + +bool +Store::update_message (MuMsg *msg, unsigned docid) +{ + auto store{reinterpret_cast(this)}; // yuk. + + GError *gerr{}; + const auto docid2{add_or_update_msg (store, docid, msg, &gerr)}; + + if (G_UNLIKELY(docid != docid2)) + throw Error{Error::Code::Internal, "failed to update message", + gerr ? gerr->message : "something went wrong"}; + + return true; +} + + bool Store::remove_message (const std::string& path) { diff --git a/lib/mu-store.hh b/lib/mu-store.hh index f34c70b5..9eefb718 100644 --- a/lib/mu-store.hh +++ b/lib/mu-store.hh @@ -122,6 +122,16 @@ public: */ unsigned add_message (const std::string& path); + /** + * Update a message in the store. + * + * @param msg a message + * @param docid a docid + * + * @return false in case of failure; true ottherwise. + */ + bool update_message (MuMsg *msg, unsigned docid); + /** * Add a message to the store. *