store: use Result<Store> builder, add auto upgrade
Make it a Result type, and add auto-upgrade (not enabled yet) Update dependents.
This commit is contained in:
@ -116,16 +116,17 @@ report_error(const Mu::Error& err) noexcept
|
||||
MuError
|
||||
Mu::mu_cmd_server(const MuConfig* opts, GError** err)
|
||||
try {
|
||||
Store store{mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), false /*writable*/};
|
||||
Server server{store, output_sexp_stdout};
|
||||
auto store = Store::make(mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), Store::Options::Writable);
|
||||
if (!store)
|
||||
throw store.error();
|
||||
|
||||
Server server{*store, output_sexp_stdout};
|
||||
g_message("created server with store @ %s; maildir @ %s; debug-mode %s",
|
||||
store.properties().database_path.c_str(),
|
||||
store.properties().root_maildir.c_str(),
|
||||
store->properties().database_path.c_str(),
|
||||
store->properties().root_maildir.c_str(),
|
||||
opts->debug ? "yes" : "no");
|
||||
|
||||
tty = ::isatty(::fileno(stdout));
|
||||
|
||||
const auto eval = std::string{opts->commands ? "(help :full t)"
|
||||
: opts->eval ? opts->eval
|
||||
: ""};
|
||||
|
||||
31
mu/mu-cmd.cc
31
mu/mu-cmd.cc
@ -549,9 +549,13 @@ cmd_init(const MuConfig* opts, GError** err)
|
||||
++addrs;
|
||||
}
|
||||
|
||||
Mu::Store store(mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), opts->maildir, my_addrs, conf);
|
||||
auto store = Store::make_new(mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB),
|
||||
opts->maildir, my_addrs, conf);
|
||||
if (!store)
|
||||
throw store.error();
|
||||
|
||||
if (!opts->quiet) {
|
||||
cmd_info(store, opts, NULL);
|
||||
cmd_info(*store, opts, NULL);
|
||||
std::cout << "\nstore created; use the 'index' command to fill/update it.\n";
|
||||
}
|
||||
|
||||
@ -561,9 +565,11 @@ cmd_init(const MuConfig* opts, GError** err)
|
||||
static Result<void>
|
||||
cmd_find(const MuConfig* opts)
|
||||
{
|
||||
Mu::Store store{mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), true /*readonly*/};
|
||||
|
||||
return mu_cmd_find(store, opts);
|
||||
auto store{Store::make(mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB))};
|
||||
if (!store)
|
||||
return Err(store.error());
|
||||
else
|
||||
return mu_cmd_find(*store, opts);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -582,15 +588,22 @@ typedef MuError (*writable_store_func)(Mu::Store&, const MuConfig*, GError** err
|
||||
static MuError
|
||||
with_readonly_store(readonly_store_func func, const MuConfig* opts, GError** err)
|
||||
{
|
||||
const Mu::Store store{mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), true /*readonly*/};
|
||||
return func(store, opts, err);
|
||||
auto store{Store::make(mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB))};
|
||||
if (!store)
|
||||
throw store.error();
|
||||
|
||||
return func(*store, opts, err);
|
||||
}
|
||||
|
||||
static MuError
|
||||
with_writable_store(writable_store_func func, const MuConfig* opts, GError** err)
|
||||
{
|
||||
Mu::Store store{mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), false /*!readonly*/};
|
||||
return func(store, opts, err);
|
||||
auto store{Store::make(mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB),
|
||||
Store::Options::Writable)};
|
||||
if (!store)
|
||||
throw store.error();
|
||||
|
||||
return func(*store, opts, err);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
||||
@ -32,6 +32,7 @@
|
||||
|
||||
#include "test-mu-common.hh"
|
||||
#include "mu-query.hh"
|
||||
#include "utils/mu-result.hh"
|
||||
#include "utils/mu-str.h"
|
||||
#include "utils/mu-utils.hh"
|
||||
#include "mu-store.hh"
|
||||
@ -90,7 +91,8 @@ run_and_count_matches(const std::string& xpath,
|
||||
const std::string& expr,
|
||||
Mu::QueryFlags flags = Mu::QueryFlags::None)
|
||||
{
|
||||
Mu::Store store{xpath};
|
||||
auto store{Store::make(xpath)};
|
||||
assert_valid_result(store);
|
||||
|
||||
// if (g_test_verbose()) {
|
||||
// std::cout << "==> mquery: " << store.parse_query(expr, false) << "\n";
|
||||
@ -99,7 +101,7 @@ run_and_count_matches(const std::string& xpath,
|
||||
|
||||
Mu::allow_warnings();
|
||||
|
||||
auto qres{store.run_query(expr, {}, flags)};
|
||||
auto qres{store->run_query(expr, {}, flags)};
|
||||
g_assert_true(!!qres);
|
||||
assert_no_dups(*qres);
|
||||
|
||||
@ -237,11 +239,10 @@ test_mu_query_logic(void)
|
||||
static void
|
||||
test_mu_query_accented_chars_01(void)
|
||||
{
|
||||
return;
|
||||
auto store = Store::make(DB_PATH1);
|
||||
assert_valid_result(store);
|
||||
|
||||
Store store{DB_PATH1};
|
||||
|
||||
auto qres{store.run_query("fünkÿ")};
|
||||
auto qres{store->run_query("fünkÿ")};
|
||||
g_assert_true(!!qres);
|
||||
g_assert_false(qres->empty());
|
||||
|
||||
@ -252,10 +253,6 @@ test_mu_query_accented_chars_01(void)
|
||||
}
|
||||
|
||||
assert_equal(msg->subject(), "Greetings from Lothlórien");
|
||||
const auto summ{to_string_opt_gchar(
|
||||
mu_str_summarize(msg->body_text().value_or("").c_str(), 5))};
|
||||
g_assert_true(!!summ);
|
||||
assert_equal(*summ, "Let's write some fünkÿ text using umlauts. Foo.");
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user