From b56698a113ae67c5208606bf7dd4eeea1e8cbb23 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 9 Apr 2023 11:02:58 +0300 Subject: [PATCH] test: don't "uniqify" link names during test --- lib/mu-maildir.cc | 10 ++++------ lib/utils/mu-test-utils.cc | 2 ++ lib/utils/mu-test-utils.hh | 2 +- mu/mu-cmd-find.cc | 6 +++++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/mu-maildir.cc b/lib/mu-maildir.cc index a07bb0ae..ca2546ac 100644 --- a/lib/mu-maildir.cc +++ b/lib/mu-maildir.cc @@ -155,7 +155,7 @@ get_target_fullpath(const std::string& src, const std::string& targetpath, if (auto&& res = check_subdir(src, in_cur); !res) return Err(std::move(res.error())); - char *srcfile{g_path_get_basename(src.c_str())}; + const auto srcfile{to_string_gchar(g_path_get_basename(src.c_str()))}; /* create targetpath; note: make the filename *cough* unique by * including a hash of the srcname in the targetname. This helps if @@ -165,15 +165,13 @@ get_target_fullpath(const std::string& src, const std::string& targetpath, if (unique_names) fulltargetpath = join_paths(targetpath, in_cur ? "cur" : "new", - format("%u_%s", + format("%08x-%s", g_str_hash(src.c_str()), - srcfile)); + srcfile.c_str())); else fulltargetpath = join_paths(targetpath, in_cur ? "cur" : "new", - srcfile); - g_free(srcfile); - + srcfile.c_str()); return fulltargetpath; } diff --git a/lib/utils/mu-test-utils.cc b/lib/utils/mu-test-utils.cc index 8e049b24..4a0288a4 100644 --- a/lib/utils/mu-test-utils.cc +++ b/lib/utils/mu-test-utils.cc @@ -93,6 +93,8 @@ black_hole(void) void Mu::mu_test_init(int *argc, char ***argv) { + g_setenv("MU_TEST", "yes", TRUE); + g_test_init(argc, argv, NULL); if (!g_test_verbose()) diff --git a/lib/utils/mu-test-utils.hh b/lib/utils/mu-test-utils.hh index ffb0662c..2db89b9a 100644 --- a/lib/utils/mu-test-utils.hh +++ b/lib/utils/mu-test-utils.hh @@ -36,7 +36,7 @@ static inline std::string test_random_tmpdir() { } /** - * mu wrapper for g_test_init + * mu wrapper for g_test_init. Sets environment variable MU_TEST to 1. * * @param argc * @param argv diff --git a/mu/mu-cmd-find.cc b/mu/mu-cmd-find.cc index cbab1371..e340a6d8 100644 --- a/mu/mu-cmd-find.cc +++ b/mu/mu-cmd-find.cc @@ -178,7 +178,11 @@ output_link(const Option& msg, const OutputInfo& info, const Options& o else if (info.footer) return true; - if (auto&& res = maildir_link(msg->path(), opts.find.linksdir); !res) { + /* during test, do not create "unique names" (i.e., names with path + * hashes), so we get a predictable result */ + const auto unique_names{!g_getenv("MU_TEST")&&!g_test_initialized()}; + + if (auto&& res = maildir_link(msg->path(), opts.find.linksdir, unique_names); !res) { res.error().fill_g_error(err); return false; }