message: implement update-after-move

Allow for in-place updating of a moved document; i.e., without re-parsing
This commit is contained in:
Dirk-Jan C. Binnema 2022-04-22 08:13:09 +03:00
parent a548cac2d0
commit a8a3a0c3bf
2 changed files with 29 additions and 3 deletions

View File

@ -687,3 +687,20 @@ Message::mtime() const
}
Result<void>
Message::update_after_move(const std::string& new_path,
const std::string& new_maildir,
Flags new_flags)
{
const auto statbuf{get_statbuf(new_path)};
if (!statbuf)
return Err(statbuf.error());
priv_->doc.add(Field::Id::Path, new_path);
priv_->doc.add(Field::Id::Maildir, new_maildir);
priv_->doc.add(new_flags);
return Ok();
}

View File

@ -29,6 +29,7 @@
#include "mu-fields.hh"
#include "mu-document.hh"
#include "mu-message-part.hh"
#include <xapian.h>
#include "utils/mu-utils.hh"
#include "utils/mu-option.hh"
@ -87,7 +88,6 @@ public:
return Err(Mu::Error(Error::Code::Message, "failed to create message"));
}
/**
* Construct a message based on a Message::Document
*
@ -265,7 +265,6 @@ public:
return document().string_vec_value(Field::Id::References);
}
/*
* Convert to Sexp
*/
@ -280,10 +279,20 @@ public:
Mu::Sexp::List to_sexp_list() const;
Mu::Sexp to_sexp() const;
/*
* And some non-const message, for updating an existing
* message after a file-system move.
*
* @return Ok or an error.
*/
Result<void> update_after_move(const std::string& new_path,
const std::string& new_maildir,
Flags new_flags);
/*
* Below require a file-backed message, which is a relatively slow
* if there isn't one already; see load_mime_message()
*
*/
/**