From 4171fe14c3e5dcf0d5e098091aa533a60b4f6a11 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Thu, 6 Jul 2023 21:33:01 +0300 Subject: [PATCH] store: removing trailing / for root_maildir Other code depends on that. --- lib/mu-store.cc | 16 +++++++++++++--- lib/tests/test-mu-store-query.cc | 4 +++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/mu-store.cc b/lib/mu-store.cc index 8700aec1..d5571fa3 100644 --- a/lib/mu-store.cc +++ b/lib/mu-store.cc @@ -52,6 +52,16 @@ static_assert(std::is_same::value, "wrong type for Sto // Properties constexpr auto ExpectedSchemaVersion = MU_STORE_SCHEMA_VERSION; +static std::string +remove_slash(const std::string& str) +{ + auto clean{str}; + while (clean[clean.length() - 1] == '/') + clean.pop_back(); + + return clean; +} + struct Store::Private { Private(const std::string& path, bool readonly): @@ -59,7 +69,7 @@ struct Store::Private { : XapianDb::Flavor::Open)}, config_{xapian_db_}, contacts_cache_{config_}, - root_maildir_{config_.get()} + root_maildir_{remove_slash(config_.get())} {} Private(const std::string& path, const std::string& root_maildir, @@ -67,7 +77,7 @@ struct Store::Private { xapian_db_{make_db(path, XapianDb::Flavor::CreateOverwrite)}, config_{make_config(xapian_db_, root_maildir, conf)}, contacts_cache_{config_}, - root_maildir_{config_.get()} + root_maildir_{remove_slash(config_.get())} {} ~Private() try { @@ -123,7 +133,7 @@ struct Store::Private { if (conf) config.import_configurable(*conf); - config.set(root_maildir); + config.set(remove_slash(root_maildir)); config.set(ExpectedSchemaVersion); return config; diff --git a/lib/tests/test-mu-store-query.cc b/lib/tests/test-mu-store-query.cc index 308e44a2..c6a4c5d3 100644 --- a/lib/tests/test-mu-store-query.cc +++ b/lib/tests/test-mu-store-query.cc @@ -42,7 +42,9 @@ static Store make_test_store(const std::string& test_path, const TestMap& test_map, const StringVec &personal_addresses) { - std::string maildir = test_path + "/Maildir"; + std::string maildir = test_path + "/Maildir/"; + // note the trailing '/' + g_test_bug("2513"); /* write messages to disk */ for (auto&& item: test_map) {