From c6fff6a281c3886c5a0acf6c87fdc01bea46a8ae Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 1 Jul 2023 18:20:51 +0300 Subject: [PATCH] all: update for API changes (config etc.) Use the new & improved APIs. --- guile/mu-guile.cc | 4 +-- lib/index/mu-indexer.cc | 13 ++++---- lib/message/mu-document.hh | 2 +- lib/mu-query-results.hh | 2 +- lib/mu-query.cc | 17 ++++------ lib/mu-server.cc | 6 ++-- lib/tests/bench-indexer.cc | 2 +- lib/tests/test-mu-store-query.cc | 12 +++++--- lib/tests/test-mu-store.cc | 53 +++++++++++++++++--------------- lib/tests/test-parser.cc | 2 +- lib/tests/test-query.cc | 2 +- lib/utils/mu-error.hh | 2 ++ lib/utils/mu-result.hh | 6 +--- mu/mu-cmd-index.cc | 6 ++-- mu/mu-cmd-server.cc | 4 +-- mu/mu.cc | 6 +++- 16 files changed, 72 insertions(+), 67 deletions(-) diff --git a/guile/mu-guile.cc b/guile/mu-guile.cc index 4a295d10..d311036c 100644 --- a/guile/mu-guile.cc +++ b/guile/mu-guile.cc @@ -88,9 +88,9 @@ mu_guile_init_instance(const std::string& muhome) try { StoreSingleton.emplace(std::move(store.value())); g_debug("mu-guile: opened store @ %s (n=%zu); maildir: %s", - StoreSingleton->properties().database_path.c_str(), + StoreSingleton->path().c_str(), StoreSingleton->size(), - StoreSingleton->properties().root_maildir.c_str()); + StoreSingleton->root_maildir().c_str()); return true; diff --git a/lib/index/mu-indexer.cc b/lib/index/mu-indexer.cc index 8d961549..756fcda5 100644 --- a/lib/index/mu-indexer.cc +++ b/lib/index/mu-indexer.cc @@ -78,14 +78,15 @@ private: struct Indexer::Private { Private(Mu::Store& store) - : store_{store}, scanner_{store_.properties().root_maildir, - [this](auto&& path, auto&& statbuf, auto&& info) { + : store_{store}, scanner_{store_.root_maildir(), + [this](auto&& path, + auto&& statbuf, auto&& info) { return handler(path, statbuf, info); }}, - max_message_size_{store_.properties().max_message_size} { + max_message_size_{store_.config().get()} { g_message("created indexer for %s -> %s (batch-size: %zu)", - store.properties().root_maildir.c_str(), - store.properties().database_path.c_str(), store.properties().batch_size); + store.root_maildir().c_str(), + store.path().c_str(), store.config().get()); } ~Private() { @@ -410,7 +411,7 @@ Indexer::~Indexer() = default; bool Indexer::start(const Indexer::Config& conf) { - const auto mdir{priv_->store_.properties().root_maildir}; + const auto mdir{priv_->store_.root_maildir()}; if (G_UNLIKELY(access(mdir.c_str(), R_OK) != 0)) { g_critical("'%s' is not readable: %s", mdir.c_str(), g_strerror(errno)); return false; diff --git a/lib/message/mu-document.hh b/lib/message/mu-document.hh index 4cfe2442..7e7d9cc9 100644 --- a/lib/message/mu-document.hh +++ b/lib/message/mu-document.hh @@ -23,8 +23,8 @@ #include #include #include -#include "utils/mu-xapian-utils.hh" +#include "mu-xapian-db.hh" #include "mu-fields.hh" #include "mu-priority.hh" #include "mu-flags.hh" diff --git a/lib/mu-query-results.hh b/lib/mu-query-results.hh index 7b8a72e1..4b3875ba 100644 --- a/lib/mu-query-results.hh +++ b/lib/mu-query-results.hh @@ -38,7 +38,7 @@ #include #include -#include +#include #include diff --git a/lib/mu-query.cc b/lib/mu-query.cc index 8be9052c..1147319b 100644 --- a/lib/mu-query.cc +++ b/lib/mu-query.cc @@ -33,7 +33,7 @@ #include "mu-query-match-deciders.hh" #include "mu-query-threads.hh" #include -#include "utils/mu-xapian-utils.hh" +#include "mu-xapian-db.hh" using namespace Mu; @@ -60,9 +60,6 @@ struct Query::Private { Option run(const std::string& expr, Field::Id sortfield_id, QueryFlags qflags, size_t maxnum) const; - - size_t store_size() const { return store_.database().get_doccount(); } - const Store& store_; const Parser parser_; }; @@ -87,8 +84,7 @@ Query::Private::make_enquire(const std::string& expr, Field::Id sortfield_id, QueryFlags qflags) const { - Xapian::Enquire enq{store_.database()}; - + auto enq{store_.xapian_db().enquire()}; if (expr.empty() || expr == R"("")") enq.set_query(Xapian::Query::MatchAll); else { @@ -110,7 +106,7 @@ Query::Private::make_related_enquire(const StringSet& thread_ids, Field::Id sortfield_id, QueryFlags qflags) const { - Xapian::Enquire enq{store_.database()}; + auto enq{store_.xapian_db().enquire()}; std::vector qvec; for (auto&& t : thread_ids) qvec.emplace_back(field_from_id(Field::Id::ThreadId).xapian_term(t)); @@ -235,7 +231,7 @@ Query::Private::run_related(const std::string& expr, return make_related_enquire(minfo.thread_ids, sortfield_id, qflags); }); - const auto r_mset{r_enq.get_mset(0, threading ? store_size() : maxnum, {}, + const auto r_mset{r_enq.get_mset(0, threading ? store_.size() : maxnum, {}, make_related_decider(qflags, minfo).get())}; auto qres{QueryResults{r_mset, std::move(minfo.matches)}}; return threading ? run_threaded(std::move(qres), r_enq, qflags, maxnum) : qres; @@ -245,7 +241,7 @@ Option Query::Private::run(const std::string& expr, Field::Id sortfield_id, QueryFlags qflags, size_t maxnum) const { - const auto eff_maxnum{maxnum == 0 ? store_size() : maxnum}; + const auto eff_maxnum{maxnum == 0 ? store_.size() : maxnum}; if (any_of(qflags & QueryFlags::IncludeRelated)) return run_related(expr, sortfield_id, qflags, eff_maxnum); @@ -273,7 +269,6 @@ Query::run(const std::string& expr, Field::Id sortfield_id, return Result(Err(Error::Code::Query, "failed to run query")); }); - } size_t @@ -282,7 +277,7 @@ Query::count(const std::string& expr) const return xapian_try( [&] { const auto enq{priv_->make_enquire(expr, {}, {})}; - auto mset{enq.get_mset(0, priv_->store_size())}; + auto mset{enq.get_mset(0, priv_->store_.size())}; mset.fetch(); return mset.size(); }, diff --git a/lib/mu-server.cc b/lib/mu-server.cc index b56cf910..d4a6a65c 100644 --- a/lib/mu-server.cc +++ b/lib/mu-server.cc @@ -933,7 +933,7 @@ Server::Private::ping_handler(const Command& cmd) if (storecount == (unsigned)-1) throw Error{Error::Code::Store, "failed to read store"}; Sexp addrs; - for (auto&& addr : store().properties().personal_addresses) + for (auto&& addr : store().config().get()) addrs.add(addr); output_sexp(Sexp() @@ -942,8 +942,8 @@ Server::Private::ping_handler(const Command& cmd) Sexp().put_props( ":version", VERSION, ":personal-addresses", std::move(addrs), - ":database-path", store().properties().database_path, - ":root-maildir", store().properties().root_maildir, + ":database-path", store().path(), + ":root-maildir", store().root_maildir(), ":doccount", storecount))); } diff --git a/lib/tests/bench-indexer.cc b/lib/tests/bench-indexer.cc index d2a2a180..ea0ebe22 100644 --- a/lib/tests/bench-indexer.cc +++ b/lib/tests/bench-indexer.cc @@ -465,7 +465,7 @@ benchmark_indexer(gconstpointer testdata) auto start = Clock::now(); { - auto store{Store::make_new(BENCH_STORE, BENCH_MAILDIRS, {}, {})}; + auto store{Store::make_new(BENCH_STORE, BENCH_MAILDIRS)}; g_assert_true(!!store); Indexer::Config conf{}; conf.max_threads = tdata->num_threads; diff --git a/lib/tests/test-mu-store-query.cc b/lib/tests/test-mu-store-query.cc index fec08678..308e44a2 100644 --- a/lib/tests/test-mu-store-query.cc +++ b/lib/tests/test-mu-store-query.cc @@ -64,7 +64,11 @@ make_test_store(const std::string& test_path, const TestMap& test_map, } /* make the store */ - auto store = Store::make_new(test_path, maildir, personal_addresses, {}); + MemDb mdb; + Config conf{mdb}; + conf.set(personal_addresses); + + auto store = Store::make_new(test_path, maildir, conf); assert_valid_result(store); /* index the messages */ @@ -544,9 +548,9 @@ Boo! /* create maildir with message */ TempDir tdir; auto store{make_test_store(tdir.path(), test_msgs, {})}; - g_debug("%s", store.properties().root_maildir.c_str()); + g_debug("%s", store.root_maildir().c_str()); /* ensure we have a proper maildir, with new/, cur/ */ - auto mres = maildir_mkdir(store.properties().root_maildir + "/inbox"); + auto mres = maildir_mkdir(store.root_maildir() + "/inbox"); assert_valid_result(mres); g_assert_cmpuint(store.size(), ==, 1U); @@ -572,7 +576,7 @@ Boo! const auto& moved_msg{moved_msgs->at(0).second}; const auto new_path = moved_msg.path(); if (!rename) - assert_equal(new_path, store.properties().root_maildir + "/inbox/cur/msg:2,S"); + assert_equal(new_path, store.root_maildir() + "/inbox/cur/msg:2,S"); g_assert_cmpuint(store.size(), ==, 1); g_assert_false(::access(old_path.c_str(), F_OK) == 0); g_assert_true(::access(new_path.c_str(), F_OK) == 0); diff --git a/lib/tests/test-mu-store.cc b/lib/tests/test-mu-store.cc index 872c56e3..87a79ebb 100644 --- a/lib/tests/test-mu-store.cc +++ b/lib/tests/test-mu-store.cc @@ -1,5 +1,5 @@ /* -** Copyright (C) 2008-2022 Dirk-Jan C. Binnema +** Copyright (C) 2008-2023 Dirk-Jan C. Binnema ** ** 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 @@ -45,37 +45,36 @@ static void test_store_ctor_dtor() { TempDir tempdir; - auto store{Store::make_new(tempdir.path(), "/tmp", {}, {})}; + auto store{Store::make_new(tempdir.path(), "/tmp")}; assert_valid_result(store); g_assert_true(store->empty()); g_assert_cmpuint(0, ==, store->size()); - g_assert_cmpstr(MU_STORE_SCHEMA_VERSION, ==, - store->properties().schema_version.c_str()); + g_assert_cmpuint(MU_STORE_SCHEMA_VERSION, ==, + store->config().get()); } - - static void test_store_reinit() { TempDir tempdir; { - Store::Config conf{}; - conf.max_message_size = 1234567; - conf.batch_size = 7654321; + MemDb mdb; + Config conf{mdb}; + conf.set(1234567); + conf.set(7654321); + conf.set( + StringVec{ "foo@example.com", "bar@example.com" }); - StringVec my_addresses{ "foo@example.com", "bar@example.com" }; - - auto store{Store::make_new(tempdir.path(), MuTestMaildir, my_addresses, conf)}; + auto store{Store::make_new(tempdir.path(), MuTestMaildir, conf)}; assert_valid_result(store); g_assert_true(store->empty()); g_assert_cmpuint(0, ==, store->size()); - g_assert_cmpstr(MU_STORE_SCHEMA_VERSION, ==, - store->properties().schema_version.c_str()); + g_assert_cmpuint(MU_STORE_SCHEMA_VERSION, ==, + store->config().get()); const auto msgpath{MuTestMaildir + "/cur/1283599333.1840_11.cthulhu!2,"}; const auto id = store->add_message(msgpath); @@ -92,11 +91,13 @@ test_store_reinit() assert_valid_result(store); g_assert_true(store->empty()); - assert_equal(store->properties().database_path, tempdir.path()); - g_assert_cmpuint(store->properties().batch_size,==,7654321); - g_assert_cmpuint(store->properties().max_message_size,==,1234567); + assert_equal(store->path(), tempdir.path()); + assert_equal(store->root_maildir(), MuTestMaildir); - const auto addrs{store->properties().personal_addresses}; + g_assert_cmpuint(store->config().get(),==,7654321); + g_assert_cmpuint(store->config().get(),==,1234567); + + const auto addrs{store->config().get()}; g_assert_cmpuint(addrs.size(),==,2); g_assert_true(seq_some(addrs, [](auto&& a){return a=="foo@example.com";})); g_assert_true(seq_some(addrs, [](auto&& a){return a=="bar@example.com";})); @@ -116,9 +117,12 @@ test_store_add_count_remove() { TempDir tempdir{false}; - auto store{Store::make_new(tempdir.path() + "/xapian", MuTestMaildir, {}, {})}; + auto store{Store::make_new(tempdir.path() + "/xapian", MuTestMaildir)}; assert_valid_result(store); + assert_equal(store->path(), tempdir.path() + "/xapian"); + assert_equal(store->root_maildir(), MuTestMaildir); + const auto msgpath{MuTestMaildir + "/cur/1283599333.1840_11.cthulhu!2,"}; const auto id1 = store->add_message(msgpath); assert_valid_result(id1); @@ -184,7 +188,7 @@ statement you can use something like: goto * instructions[pOp->opcode]; )"; TempDir tempdir; - auto store{Store::make_new(tempdir.path(), "/home/test/Maildir", {}, {})}; + auto store{Store::make_new(tempdir.path(), "/home/test/Maildir")}; assert_valid_result(store); const auto msgpath{"/home/test/Maildir/inbox/cur/1649279256.107710_1.evergrey:2,S"}; @@ -269,7 +273,7 @@ World! )"; TempDir tempdir; - auto store{Store::make_new(tempdir.path(), "/home/test/Maildir", {}, {})}; + auto store{Store::make_new(tempdir.path(), "/home/test/Maildir")}; assert_valid_result(store); auto message{Message::make_from_text( @@ -343,7 +347,7 @@ Yes, that would be excellent. // Index it into a store. TempDir tempdir; - auto store{Store::make_new(tempdir.path(), tempdir2.path() + "/Maildir", {}, {})}; + auto store{Store::make_new(tempdir.path(), tempdir2.path() + "/Maildir")}; assert_valid_result(store); store->indexer().start({}); @@ -414,7 +418,7 @@ Yes, that would be excellent. auto msg3_path = tempdir2.path() + "/Maildir/b/cur/msgdef:2,RS"; TempDir tempdir; - auto store{Store::make_new(tempdir.path(), tempdir2.path() + "/Maildir", {}, {})}; + auto store{Store::make_new(tempdir.path(), tempdir2.path() + "/Maildir")}; assert_valid_result(store); std::vector ids; @@ -473,8 +477,7 @@ test_store_fail() { const auto store = Store::make_new("/../../root/non-existent-path/12345", - "/../../root/non-existent-path/54321", - {}, {}); + "/../../root/non-existent-path/54321"); g_assert_false(!!store); } } diff --git a/lib/tests/test-parser.cc b/lib/tests/test-parser.cc index 74b5522c..4590a28f 100644 --- a/lib/tests/test-parser.cc +++ b/lib/tests/test-parser.cc @@ -43,7 +43,7 @@ test_cases(const CaseVec& cases) { char* tmpdir = test_mu_common_get_random_tmpdir(); g_assert(tmpdir); - auto dummy_store{Store::make_new(tmpdir, "/tmp", {}, {})}; + auto dummy_store{Store::make_new(tmpdir, "/tmp")}; assert_valid_result(dummy_store); g_free(tmpdir); diff --git a/lib/tests/test-query.cc b/lib/tests/test-query.cc index d1ca0bb0..2fb6e39b 100644 --- a/lib/tests/test-query.cc +++ b/lib/tests/test-query.cc @@ -41,7 +41,7 @@ test_query() char* tdir; tdir = test_mu_common_get_random_tmpdir(); - auto store = Store::make_new(tdir, std::string{MU_TESTMAILDIR}, {}, {}); + auto store = Store::make_new(tdir, std::string{MU_TESTMAILDIR}); assert_valid_result(store); g_free(tdir); diff --git a/lib/utils/mu-error.hh b/lib/utils/mu-error.hh index 562d7c4f..a4b04d4f 100644 --- a/lib/utils/mu-error.hh +++ b/lib/utils/mu-error.hh @@ -69,6 +69,8 @@ struct Error final : public std::exception { UnverifiedSignature = err_enum(119,1,0), User = err_enum(120,1,0), Xapian = err_enum(121,1,0), + + CannotReinit = err_enum(122,1,0), }; /** diff --git a/lib/utils/mu-result.hh b/lib/utils/mu-result.hh index ee709f13..9f7d719e 100644 --- a/lib/utils/mu-result.hh +++ b/lib/utils/mu-result.hh @@ -1,5 +1,5 @@ /* -** Copyright (C) 2019-2020 Dirk-Jan C. Binnema +** Copyright (C) 2019-2023 Dirk-Jan C. Binnema ** ** 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 @@ -134,8 +134,6 @@ Err(Error::Code errcode, GError **err, const char* frm, ...) return Err(errcode, std::move(str)); } - - /** * Assert that some result has a value (for unit tests) * @@ -150,8 +148,6 @@ Err(Error::Code errcode, GError **err, const char* frm, ...) } \ } while(0) - - }// namespace Mu #endif /* MU_RESULT_HH__ */ diff --git a/mu/mu-cmd-index.cc b/mu/mu-cmd-index.cc index 93954eec..f8cf6f33 100644 --- a/mu/mu-cmd-index.cc +++ b/mu/mu-cmd-index.cc @@ -77,7 +77,7 @@ print_stats(const Indexer::Progress& stats, bool color) Result Mu::mu_cmd_index(Store& store, const Options& opts) { - const auto mdir{store.properties().root_maildir}; + const auto mdir{store.root_maildir()}; if (G_UNLIKELY(access(mdir.c_str(), R_OK) != 0)) return Err(Error::Code::File, "'%s' is not readable: %s", mdir.c_str(), g_strerror(errno)); @@ -89,8 +89,8 @@ Mu::mu_cmd_index(Store& store, const Options& opts) std::cout << "lazily "; std::cout << "indexing maildir " << col.fg(Color::Green) - << store.properties().root_maildir << col.reset() << " -> store " - << col.fg(Color::Green) << store.properties().database_path << col.reset() + << store.root_maildir() << col.reset() << " -> store " + << col.fg(Color::Green) << store.path() << col.reset() << std::endl; } diff --git a/mu/mu-cmd-server.cc b/mu/mu-cmd-server.cc index b25635fc..6c55a097 100644 --- a/mu/mu-cmd-server.cc +++ b/mu/mu-cmd-server.cc @@ -120,8 +120,8 @@ Mu::mu_cmd_server(const Mu::Options& opts) try { Server server{*store, output_sexp_stdout}; g_message("created server with store @ %s; maildir @ %s; debug-mode %s;" "readline: %s", - store->properties().database_path.c_str(), - store->properties().root_maildir.c_str(), + store->path().c_str(), + store->root_maildir().c_str(), opts.debug ? "yes" : "no", have_readline() ? "yes" : "no"); diff --git a/mu/mu.cc b/mu/mu.cc index 860e1eac..8147c7f5 100644 --- a/mu/mu.cc +++ b/mu/mu.cc @@ -71,7 +71,11 @@ handle_result(const Result& res, const Mu::Options& opts) std::cerr << "Perhaps mu is already running?\n"; break; case Error::Code::SchemaMismatch: - std::cerr << "Please (re)initialize mu with 'mu init' " + std::cerr << "Please (re)initialize mu with 'mu init'; " + << "see mu-init(1) for details\n"; + break; + case Error::Code::CannotReinit: + std::cerr << "Invoke 'mu init' without '--reinit'; " << "see mu-init(1) for details\n"; break; default: