summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2023-07-18 23:15:53 +0300
committerDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2023-07-18 23:18:21 +0300
commit6ad5cccc537fdfd82efd01b77c45591c76dc7b6f (patch)
tree64f660617ce7c03e1c0e956253a0dbcfbe4a0c13
parent885903c496d8ad572a3ff919d3c521c5e217bdba (diff)
store/index: and unit test for circular symlink
Check that we bail out early
-rw-r--r--lib/tests/test-mu-store-query.cc2
-rw-r--r--lib/tests/test-mu-store.cc36
-rw-r--r--lib/utils/mu-test-utils.cc2
-rw-r--r--meson.build4
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 c6a4c5d..2713323 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 87a79eb..c0ae517 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 <mike@example.com>
To: Raul Endymion <raul@example.com>
@@ -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 eb9579e..dd9fe1c 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 a8056cd..4182139 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())