mirror of https://github.com/djcb/mu.git
* add mu_util_guess_mu_homedir and mu_util_guess_xapian_dir and use them
This commit is contained in:
parent
d112c2c930
commit
3b87a0f9e6
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue