mu-maildir: use the new run_command0

And fix some docstrings.
This commit is contained in:
Dirk-Jan C. Binnema
2023-09-19 23:42:23 +03:00
parent b771fd6394
commit 8ba153067b
2 changed files with 10 additions and 20 deletions

View File

@ -293,19 +293,8 @@ msg_move_g_file(const std::string& src, const std::string& dst)
G_GNUC_UNUSED static Mu::Result<void> G_GNUC_UNUSED static Mu::Result<void>
msg_move_mv_file(const std::string& src, const std::string& dst) msg_move_mv_file(const std::string& src, const std::string& dst)
{ {
const auto cmdline{mu_format("/bin/mv {} {}", if (auto res{run_command0({"/bin/mv", src, dst})}; !res)
to_string_gchar(g_shell_quote(src.c_str())), return Err(Error::Code::File, "error moving {}->{}; err={}", src, dst, res.error());
to_string_gchar(g_shell_quote(dst.c_str())))};
GError *err{};
int wait_status{};
mu_debug("{}", cmdline);
if (!g_spawn_command_line_sync(cmdline.c_str(), {}, {}, &wait_status, &err))
return Err(Error::Code::File, &err, "error moving {} -> {}", src, dst);
else if (auto&& res{WEXITSTATUS(wait_status)}; res != 0)
return Err(Error::Code::File, "error moving {} -> {}; err={}",
src, dst, res);
else else
return Ok(); return Ok();
} }
@ -424,7 +413,7 @@ check_determine_target_params (const std::string& old_path,
if (any_of(newflags & Flags::New) && newflags != Flags::New) if (any_of(newflags & Flags::New) && newflags != Flags::New)
return Err(Error{Error::Code::File, return Err(Error{Error::Code::File,
"if ::New is specified, it must be the only flag"}); "if the New flag is specified, it must be the only flag"});
return Ok(); return Ok();
} }
@ -436,6 +425,8 @@ Mu::maildir_determine_target(const std::string& old_path,
Flags newflags, Flags newflags,
bool new_name) bool new_name)
{ {
newflags = flags_mail_dir_file(newflags); // filter out irrelevant flags.
/* sanity checks */ /* sanity checks */
if (const auto checked{check_determine_target_params( if (const auto checked{check_determine_target_params(
old_path, root_maildir_path, target_maildir, newflags)}; !checked) old_path, root_maildir_path, target_maildir, newflags)}; !checked)

View File

@ -1,5 +1,5 @@
/* /*
** Copyright (C) 2008-2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> ** Copyright (C) 2008-2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** **
** This program is free software; you can redistribute it and/or modify it ** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the ** under the terms of the GNU General Public License as published by the
@ -97,19 +97,18 @@ Result<void> maildir_move_message(const std::string& oldpath,
* @param old_path an absolute file system path to an existing message in an * @param old_path an absolute file system path to an existing message in an
* actual maildir * actual maildir
* @param root_maildir_path the absolete file system path under which * @param root_maildir_path the absolete file system path under which
* all maidlirs live. * all maildirs live.
* @param target_maildir the target maildir; note that this the base-level * @param target_maildir the target maildir; note that this the base-level
* Maildir, ie. /home/user/Maildir/archive, and must _not_ include the * Maildir, ie. /home/user/Maildir/archive, and must _not_ include the
* 'cur' or 'new' part. Note that the target maildir must be on the * 'cur' or 'new' part. Note that the target maildir must be on the
* same filesystem. Can be empty if the message should not be moved to * same filesystem. Can be empty if the message should not be moved to
* a different maildir; note that this may still involve a * a different maildir; note that this may still involve a
* move to another directory (say, from new/ to cur/) * move to another directory (say, from new/ to cur/)
* @param flags to set for the target (influences the filename, path). * @param flags to set for the target (influences the filename, path). Any none-Maildir/File
* flags are ignored.
* @param new_name whether to change the basename of the file * @param new_name whether to change the basename of the file
* @param err receives error information
* *
* @return Full path name of the target file or std::nullopt in case * @return Full path name of the target file or an Error
* of error
*/ */
Result<std::string> Result<std::string>
maildir_determine_target(const std::string& old_path, maildir_determine_target(const std::string& old_path,