From 6ad5cccc537fdfd82efd01b77c45591c76dc7b6f Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Tue, 18 Jul 2023 23:15:53 +0300 Subject: [PATCH] store/index: and unit test for circular symlink Check that we bail out early --- lib/tests/test-mu-store-query.cc | 2 -- lib/tests/test-mu-store.cc | 36 ++++++++++++++++++++++++++++++-- lib/utils/mu-test-utils.cc | 2 ++ meson.build | 4 ++++ 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/lib/tests/test-mu-store-query.cc b/lib/tests/test-mu-store-query.cc index c6a4c5d3..27133239 100644 --- a/lib/tests/test-mu-store-query.cc +++ b/lib/tests/test-mu-store-query.cc @@ -783,8 +783,6 @@ main(int argc, char* argv[]) { mu_test_init(&argc, &argv); - g_test_bug_base("https://github.com/djcb/mu/issues/"); - g_test_add_func("/store/query/simple", test_simple); g_test_add_func("/store/query/spam-address-components", test_spam_address_components); diff --git a/lib/tests/test-mu-store.cc b/lib/tests/test-mu-store.cc index 87a79ebb..c0ae5175 100644 --- a/lib/tests/test-mu-store.cc +++ b/lib/tests/test-mu-store.cc @@ -38,6 +38,8 @@ using namespace Mu; +using namespace std::chrono_literals; + static std::string MuTestMaildir = Mu::canonicalize_filename(MU_TESTMAILDIR, "/"); static std::string MuTestMaildir2 = Mu::canonicalize_filename(MU_TESTMAILDIR2, "/"); @@ -305,8 +307,6 @@ World! static void test_index_move() { - using namespace std::chrono_literals; - const std::string msg_text = R"(From: Valentine Michael Smith To: Raul Endymion @@ -466,6 +466,37 @@ Yes, that would be excellent. } } +static void +test_store_circular_symlink(void) +{ + allow_warnings(); + + g_test_bug("2517"); + + auto testhome{unwrap(make_temp_dir())}; + auto dbpath{runtime_path(RuntimePath::XapianDb, testhome)}; + + /* create a writable copy */ + const auto testmdir = join_paths(testhome, "test-maildir"); + auto cres1 = run_command({CP_PROGRAM, "-r", MU_TESTMAILDIR, testmdir}); + assert_valid_command(cres1); + // create a symink + auto cres2 = run_command({LN_PROGRAM, "-s", testmdir, join_paths(testmdir, "testlink")}); + assert_valid_command(cres2); + + auto&& store = unwrap(Store::make_new(dbpath, testmdir)); + store.indexer().start({}); + size_t n{}; + while (store.indexer().is_running()) { + std::this_thread::sleep_for(100ms); + g_assert_cmpuint(n++,<=,25); + } + // there will be a lot of dups.... + g_assert_false(store.empty()); + + remove_directory(testhome); +} + static void test_store_fail() @@ -496,6 +527,7 @@ main(int argc, char* argv[]) test_message_attachments); g_test_add_func("/store/index/index-move", test_index_move); g_test_add_func("/store/index/move-dups", test_store_move_dups); + g_test_add_func("/store/index/circular-symlink", test_store_circular_symlink); g_test_add_func("/store/index/fail", test_store_fail); return g_test_run(); diff --git a/lib/utils/mu-test-utils.cc b/lib/utils/mu-test-utils.cc index eb9579e1..dd9fe1c7 100644 --- a/lib/utils/mu-test-utils.cc +++ b/lib/utils/mu-test-utils.cc @@ -99,6 +99,8 @@ Mu::mu_test_init(int *argc, char ***argv) g_test_init(argc, argv, NULL); + g_test_bug_base("https://github.com/djcb/mu/issues/"); + if (!g_test_verbose()) g_log_set_handler( NULL, diff --git a/meson.build b/meson.build index a8056cdf..4182139f 100644 --- a/meson.build +++ b/meson.build @@ -144,8 +144,11 @@ endif dependency('cld2', required : false) +# note: these are for the unit-tests + cp=find_program('cp') mv=find_program('mv') +ln=find_program('ln') rm=find_program('rm') awk=find_program(['gawk', 'awk']) gzip=find_program('gzip') @@ -153,6 +156,7 @@ gzip=find_program('gzip') config_h_data.set_quoted('CP_PROGRAM', cp.full_path()) config_h_data.set_quoted('MV_PROGRAM', mv.full_path()) config_h_data.set_quoted('RM_PROGRAM', rm.full_path()) +config_h_data.set_quoted('LN_PROGRAM', ln.full_path()) config_h_data.set_quoted('AWK_PROGRAM', awk.full_path()) config_h_data.set_quoted('GZIP_PROGRAM', gzip.full_path())