From 3b87a0f9e6015f09f7e4cb8be8ffdfb59e414c57 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Tue, 2 Nov 2010 21:12:18 +0200 Subject: [PATCH] * add mu_util_guess_mu_homedir and mu_util_guess_xapian_dir and use them --- src/mu-config.c | 26 ++++---------------------- src/mu-util.c | 30 ++++++++++++++++++++++++++++++ src/mu-util.h | 24 ++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/mu-config.c b/src/mu-config.c index ad99f672..1c8d0445 100644 --- a/src/mu-config.c +++ b/src/mu-config.c @@ -27,32 +27,14 @@ #include "mu-util.h" #include "mu-config.h" - -static gchar* -guess_muhome (void) -{ - const char* home; - - home = g_getenv ("HOME"); - if (!home) - home = g_get_home_dir (); - - if (!home) - MU_WRITE_LOG ("failed to determine homedir"); - - return g_strdup_printf ("%s%c%s", home ? home : ".", G_DIR_SEPARATOR, - ".mu"); -} - static void set_group_mu_defaults (MuConfigOptions *opts) { - if (!opts->muhome) - opts->muhome = guess_muhome (); - + if (!opts->muhome) + opts->muhome = mu_util_guess_mu_homedir (); + /* note: xpath is is *not* settable from the cmdline */ - opts->xpath = g_strdup_printf ("%s%c%s", opts->muhome,G_DIR_SEPARATOR, - MU_XAPIAN_DIR_NAME); + opts->xpath = mu_util_guess_xapian_dir (opts->muhome); } diff --git a/src/mu-util.c b/src/mu-util.c index 95e4481e..f50abc39 100644 --- a/src/mu-util.c +++ b/src/mu-util.c @@ -178,6 +178,36 @@ mu_util_guess_maildir (void) } +gchar* +mu_util_guess_mu_homedir (void) +{ + const char* home; + + home = g_getenv ("HOME"); + if (!home) + home = g_get_home_dir (); + + if (!home) + MU_WRITE_LOG ("failed to determine homedir"); + + return g_strdup_printf ("%s%c%s", home ? home : ".", G_DIR_SEPARATOR, + ".mu"); +} + + +gchar* +mu_util_guess_xapian_dir (const char* muhome) +{ + gchar *homedir, *xdir; + + homedir = muhome ? g_strdup(muhome) : mu_util_guess_mu_homedir (); + xdir = g_strdup_printf ("%s%c%s", homedir, G_DIR_SEPARATOR, + MU_XAPIAN_DIR_NAME); + g_free (homedir); + + return xdir; +} + gboolean mu_util_create_dir_maybe (const gchar *path) diff --git a/src/mu-util.h b/src/mu-util.h index 6be883c4..f119ebed 100644 --- a/src/mu-util.h +++ b/src/mu-util.h @@ -51,6 +51,30 @@ char* mu_util_dir_expand (const char* path) G_GNUC_WARN_UNUSED_RESULT; char* mu_util_guess_maildir (void) G_GNUC_WARN_UNUSED_RESULT; +/** + * guess the place of the mu homedir (typically, ~/.mu). Note, this + * directory does not necessarily exist. mu_util_check_dir can be use + * to check that + * + * @return the guessed mu homedir, which needs to be freed with g_free + * when no longer needed. + */ +gchar* mu_util_guess_mu_homedir (void); + + +/** + * guess the place of the xapian database (typically, + * ~/.mu/xapian/). Note, this directory does not necessarily + * exist. mu_util_check_dir can be use to check that + * + * @param muhome the mu home directory or NULL, in which the muhome + * directoy will be guessed as well + * + * @return the guessed xapian dir, which needs to be freed with g_free + * when no longer needed. + */ +gchar* mu_util_guess_xapian_dir (const gchar *muhome); + /** * if path exists, check that's a read/writeable dir; otherwise try to