mu: support MUHOME environment variable

This commit is contained in:
Dirk-Jan C. Binnema
2022-05-28 10:59:52 +03:00
parent 926b49220e
commit b1ff292bbb
6 changed files with 46 additions and 15 deletions

View File

@ -75,8 +75,17 @@ get_output_format(const char* formatstr)
static void
set_group_mu_defaults()
{
/* If muhome is not set, we use the XDG Base Directory Specification
* locations. */
/* try to determine muhome from command-line or environment;
* note: if not specified, we use XDG defaults */
if (!MU_CONFIG.muhome) {
/* if not set explicity, try the environment */
const char* muhome;
muhome = g_getenv("MUHOME");
if (muhome)
MU_CONFIG.muhome = g_strdup(muhome);
}
if (MU_CONFIG.muhome)
expand_dir(MU_CONFIG.muhome);

View File

@ -45,14 +45,16 @@ static std::string
make_database(const std::string& testdir)
{
char* tmpdir{test_mu_common_get_random_tmpdir()};
/* use the env var rather than `--muhome` */
g_setenv("MUHOME", tmpdir, 1);
const auto cmdline{format("/bin/sh -c '"
"%s init --muhome=%s --maildir=%s --quiet ; "
"%s index --muhome=%s --quiet'",
"%s init --maildir=%s --quiet ; "
"%s index --quiet'",
MU_PROGRAM,
tmpdir,
testdir.c_str(),
MU_PROGRAM,
tmpdir)};
MU_PROGRAM)};
if (g_test_verbose())
g_printerr("\n%s\n", cmdline.c_str());
@ -61,6 +63,9 @@ make_database(const std::string& testdir)
auto xpath = g_strdup_printf("%s%c%s", tmpdir, G_DIR_SEPARATOR, "xapian");
g_free(tmpdir);
/* ensure MUHOME worked */
g_assert_cmpuint(::access(xpath, F_OK), ==, 0);
std::string dbpath{xpath};
g_free(xpath);