mirror of https://github.com/djcb/mu.git
migrate some more code to mu_format / join_paths
Let's modernize a bit.
This commit is contained in:
parent
8c11f6f71f
commit
7b38f094c4
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** Copyright (C) 2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2022-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
|
||||||
|
@ -21,6 +21,7 @@
|
||||||
#include "mu-mime-object.hh"
|
#include "mu-mime-object.hh"
|
||||||
#include "gmime/gmime-message.h"
|
#include "gmime/gmime-message.h"
|
||||||
#include "utils/mu-utils.hh"
|
#include "utils/mu-utils.hh"
|
||||||
|
#include "utils/mu-utils-file.hh"
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -237,7 +238,7 @@ MimeCryptoContext::setup_gpg_test(const std::string& testpath)
|
||||||
{
|
{
|
||||||
/* setup clean environment for testing; inspired by gmime */
|
/* setup clean environment for testing; inspired by gmime */
|
||||||
|
|
||||||
g_setenv ("GNUPGHOME", format("%s/.gnupg", testpath.c_str()).c_str(), 1);
|
g_setenv ("GNUPGHOME", join_paths(testpath, ".gnupg").c_str(), 1);
|
||||||
|
|
||||||
/* disable environment variables that gpg-agent uses for pinentry */
|
/* disable environment variables that gpg-agent uses for pinentry */
|
||||||
g_unsetenv ("DBUS_SESSION_BUS_ADDRESS");
|
g_unsetenv ("DBUS_SESSION_BUS_ADDRESS");
|
||||||
|
|
|
@ -359,7 +359,7 @@ to_string(const ThreadPath& tpath, size_t digits)
|
||||||
|
|
||||||
bool first{true};
|
bool first{true};
|
||||||
for (auto&& segm : tpath) {
|
for (auto&& segm : tpath) {
|
||||||
str += format("%s%0*x", first ? "" : ":", (int)digits, segm);
|
str += mu_format("{}{:0{}x}", first ? "" : ":", segm, digits);
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -257,8 +257,8 @@ Query::run(const std::string& expr, Field::Id sortfield_id,
|
||||||
g_return_val_if_fail(none_of(qflags & QueryFlags::Leader),
|
g_return_val_if_fail(none_of(qflags & QueryFlags::Leader),
|
||||||
Err(Error::Code::InvalidArgument, "cannot pass Leader flag"));
|
Err(Error::Code::InvalidArgument, "cannot pass Leader flag"));
|
||||||
|
|
||||||
StopWatch sw{format(
|
StopWatch sw{mu_format(
|
||||||
"ran query '%s'; related: %s; threads: %s; max-size: %zu", expr.c_str(),
|
"ran query '{}'; related: {}; threads: {}; max-size: {}", expr,
|
||||||
any_of(qflags & QueryFlags::IncludeRelated) ? "yes" : "no",
|
any_of(qflags & QueryFlags::IncludeRelated) ? "yes" : "no",
|
||||||
any_of(qflags & QueryFlags::Threading) ? "yes" : "no", maxnum)};
|
any_of(qflags & QueryFlags::Threading) ? "yes" : "no", maxnum)};
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@
|
||||||
#include "mu-store.hh"
|
#include "mu-store.hh"
|
||||||
|
|
||||||
#include "utils/mu-utils.hh"
|
#include "utils/mu-utils.hh"
|
||||||
|
#include "utils/mu-utils-file.hh"
|
||||||
|
|
||||||
#include "utils/mu-option.hh"
|
#include "utils/mu-option.hh"
|
||||||
#include "utils/mu-command-handler.hh"
|
#include "utils/mu-command-handler.hh"
|
||||||
#include "utils/mu-readline.hh"
|
#include "utils/mu-readline.hh"
|
||||||
|
@ -429,8 +431,7 @@ maybe_add_attachment(Message& message, const MessagePart& part, size_t index)
|
||||||
throw cache_path.error();
|
throw cache_path.error();
|
||||||
|
|
||||||
const auto cooked_name{part.cooked_filename()};
|
const auto cooked_name{part.cooked_filename()};
|
||||||
const auto fname{format("%s/%s", cache_path->c_str(),
|
const auto fname{join_paths(*cache_path, cooked_name.value_or("part"))};
|
||||||
cooked_name.value_or("part").c_str())};
|
|
||||||
|
|
||||||
const auto res = part.to_file(fname, true);
|
const auto res = part.to_file(fname, true);
|
||||||
if (!res)
|
if (!res)
|
||||||
|
@ -528,7 +529,7 @@ Server::Private::contacts_handler(const Command& cmd)
|
||||||
|
|
||||||
Sexp seq;
|
Sexp seq;
|
||||||
seq.put_props(":contacts", contacts,
|
seq.put_props(":contacts", contacts,
|
||||||
":tstamp", format("%" G_GINT64_FORMAT, g_get_monotonic_time()));
|
":tstamp", mu_format("{}", g_get_monotonic_time()));
|
||||||
|
|
||||||
/* dump the contacts cache as a giant sexp */
|
/* dump the contacts cache as a giant sexp */
|
||||||
mu_debug("sending {} of {} contact(s)", n, store().contacts_cache().size());
|
mu_debug("sending {} of {} contact(s)", n, store().contacts_cache().size());
|
||||||
|
@ -646,8 +647,8 @@ Server::Private::find_handler(const Command& cmd)
|
||||||
if (threads)
|
if (threads)
|
||||||
qflags |= QueryFlags::Threading;
|
qflags |= QueryFlags::Threading;
|
||||||
|
|
||||||
StopWatch sw{format("%s (indexing: %s)", __func__,
|
StopWatch sw{mu_format("{} (indexing: {})", __func__,
|
||||||
indexer().is_running() ? "yes" : "no")};
|
indexer().is_running() ? "yes" : "no")};
|
||||||
|
|
||||||
std::lock_guard l{store_.lock()};
|
std::lock_guard l{store_.lock()};
|
||||||
auto qres{store_.run_query(q, sort_field_id, qflags, maxnum)};
|
auto qres{store_.run_query(q, sort_field_id, qflags, maxnum)};
|
||||||
|
@ -670,11 +671,11 @@ Server::Private::help_handler(const Command& cmd)
|
||||||
auto&& info_map{command_handler_.info_map()};
|
auto&& info_map{command_handler_.info_map()};
|
||||||
|
|
||||||
if (command.empty()) {
|
if (command.empty()) {
|
||||||
std::cout << ";; Commands are single-line s-expressions of the form\n"
|
mu_println(";; Commands are single-line s-expressions of the form\n"
|
||||||
<< ";; (<command-name> :param1 val1 :param2 val2 ...)\n"
|
";; (<command-name> :param1 val1 :param2 val2 ...)\n"
|
||||||
<< ";; For instance:\n;; (help :command mkdir)\n"
|
";; For instance:\n;; (help :command mkdir)\n"
|
||||||
<< ";; to get detailed information about the 'mkdir' command\n;;\n";
|
";; to get more information about the 'mkdir' command\n;;\n"
|
||||||
std::cout << ";; The following commands are available:\n\n";
|
";; The following commands are available:");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> names;
|
std::vector<std::string> names;
|
||||||
|
@ -689,24 +690,18 @@ Server::Private::help_handler(const Command& cmd)
|
||||||
if (!command.empty() && name != command)
|
if (!command.empty() && name != command)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!command.empty())
|
mu_println(";; {:<12} -- {}", name, info.docstring);
|
||||||
std::cout << ";; "
|
|
||||||
<< format("%-10s -- %s\n", name.c_str(), info.docstring.c_str());
|
|
||||||
else
|
|
||||||
std::cout << ";; " << name.c_str() << " -- " << info.docstring.c_str()
|
|
||||||
<< '\n';
|
|
||||||
if (!full)
|
if (!full)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (auto&& argname : info.sorted_argnames()) {
|
for (auto&& argname : info.sorted_argnames()) {
|
||||||
const auto& arg{info.args.find(argname)};
|
const auto& arg{info.args.find(argname)};
|
||||||
std::cout << ";; "
|
mu_println(";; {:<17} :: {:<24} -- {}",
|
||||||
<< format("%-17s : %-24s ",
|
arg->first, to_string(arg->second),
|
||||||
arg->first.c_str(),
|
arg->second.docstring);
|
||||||
to_string(arg->second).c_str());
|
|
||||||
std::cout << " " << arg->second.docstring << "\n";
|
|
||||||
}
|
}
|
||||||
std::cout << ";;\n";
|
mu_println(";;");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -766,8 +761,8 @@ Server::Private::mkdir_handler(const Command& cmd)
|
||||||
* requested */
|
* requested */
|
||||||
if (update)
|
if (update)
|
||||||
output_sexp(Sexp().put_props(":info", "mkdir",
|
output_sexp(Sexp().put_props(":info", "mkdir",
|
||||||
":message", format("%s has been created",
|
":message",
|
||||||
path.c_str())));
|
mu_format("{} has been created", path)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -914,7 +909,7 @@ Server::Private::queries_handler(const Command& cmd)
|
||||||
Sexp qresults;
|
Sexp qresults;
|
||||||
for (auto&& q : queries) {
|
for (auto&& q : queries) {
|
||||||
const auto count{store_.count_query(q)};
|
const auto count{store_.count_query(q)};
|
||||||
const auto unreadq{format("flag:unread AND (%s)", q.c_str())};
|
const auto unreadq{mu_format("flag:unread AND ({})", q)};
|
||||||
const auto unread{store_.count_query(unreadq)};
|
const auto unread{store_.count_query(unreadq)};
|
||||||
qresults.add(Sexp().put_props(":query", q,
|
qresults.add(Sexp().put_props(":query", q,
|
||||||
":count", count,
|
":count", count,
|
||||||
|
@ -992,8 +987,7 @@ Server::Private::view_mark_as_read(Store::Id docid, Message&& msg, bool rename)
|
||||||
void
|
void
|
||||||
Server::Private::view_handler(const Command& cmd)
|
Server::Private::view_handler(const Command& cmd)
|
||||||
{
|
{
|
||||||
StopWatch sw{format("%s (indexing: %s)", __func__,
|
StopWatch sw{mu_format("{} (indexing: {})", __func__, indexer().is_running())};
|
||||||
indexer().is_running() ? "yes" : "no")};
|
|
||||||
|
|
||||||
const auto mark_as_read{cmd.boolean_arg(":mark-as-read")};
|
const auto mark_as_read{cmd.boolean_arg(":mark-as-read")};
|
||||||
/* for now, do _not_ rename, as it seems to confuse mbsync */
|
/* for now, do _not_ rename, as it seems to confuse mbsync */
|
||||||
|
|
|
@ -95,7 +95,7 @@ guess_nick(const Contact& contact)
|
||||||
nicks.emplace(nick, 0);
|
nicks.emplace(nick, 0);
|
||||||
else {
|
else {
|
||||||
++it->second;
|
++it->second;
|
||||||
nick = format("%s%zu", nick.c_str(), ++it->second);
|
nick = mu_format("{}{}", nick, ++it->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nick;
|
return nick;
|
||||||
|
|
|
@ -38,7 +38,7 @@ save_part(const Message::Part& part, size_t idx, const Options& opts)
|
||||||
* cooking */
|
* cooking */
|
||||||
const auto path{targetdir +
|
const auto path{targetdir +
|
||||||
part.cooked_filename(opts.extract.uncooked)
|
part.cooked_filename(opts.extract.uncooked)
|
||||||
.value_or(format("part-%zu", idx))};
|
.value_or(mu_format("part-{}", idx))};
|
||||||
|
|
||||||
if (auto&& res{part.to_file(path, opts.extract.overwrite)}; !res)
|
if (auto&& res{part.to_file(path, opts.extract.overwrite)}; !res)
|
||||||
return Err(res.error());
|
return Err(res.error());
|
||||||
|
|
Loading…
Reference in New Issue