mirror of https://github.com/djcb/mu.git
all: update for API changes (config etc.)
Use the new & improved APIs.
This commit is contained in:
parent
2acc1c2271
commit
c6fff6a281
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<Mu::Config::Id::MaxMessageSize>()} {
|
||||
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<Mu::Config::Id::BatchSize>());
|
||||
}
|
||||
|
||||
~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;
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
#include <utility>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "utils/mu-xapian-utils.hh"
|
||||
|
||||
#include "mu-xapian-db.hh"
|
||||
#include "mu-fields.hh"
|
||||
#include "mu-priority.hh"
|
||||
#include "mu-flags.hh"
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
#include <utils/mu-utils.hh>
|
||||
#include <utils/mu-option.hh>
|
||||
#include <utils/mu-xapian-utils.hh>
|
||||
#include <mu-xapian-db.hh>
|
||||
|
||||
#include <message/mu-message.hh>
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include "mu-query-match-deciders.hh"
|
||||
#include "mu-query-threads.hh"
|
||||
#include <mu-xapian.hh>
|
||||
#include "utils/mu-xapian-utils.hh"
|
||||
#include "mu-xapian-db.hh"
|
||||
|
||||
using namespace Mu;
|
||||
|
||||
|
@ -60,9 +60,6 @@ struct Query::Private {
|
|||
Option<QueryResults> 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<Xapian::Query> 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<QueryResults>
|
|||
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<QueryResults>(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();
|
||||
},
|
||||
|
|
|
@ -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<Config::Id::PersonalAddresses>())
|
||||
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)));
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<Config::Id::PersonalAddresses>(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);
|
||||
|
|
|
@ -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
|
||||
** 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<Config::Id::SchemaVersion>());
|
||||
}
|
||||
|
||||
|
||||
|
||||
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<Config::Id::MaxMessageSize>(1234567);
|
||||
conf.set<Config::Id::BatchSize>(7654321);
|
||||
conf.set<Config::Id::PersonalAddresses>(
|
||||
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<Config::Id::SchemaVersion>());
|
||||
|
||||
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<Config::Id::BatchSize>(),==,7654321);
|
||||
g_assert_cmpuint(store->config().get<Config::Id::MaxMessageSize>(),==,1234567);
|
||||
|
||||
const auto addrs{store->config().get<Config::Id::PersonalAddresses>()};
|
||||
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<Store::Id> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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),
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** Copyright (C) 2019-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2019-2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** 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__ */
|
||||
|
|
|
@ -77,7 +77,7 @@ print_stats(const Indexer::Progress& stats, bool color)
|
|||
Result<void>
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
6
mu/mu.cc
6
mu/mu.cc
|
@ -71,7 +71,11 @@ handle_result(const Result<void>& 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:
|
||||
|
|
Loading…
Reference in New Issue