From 84484737324578b0addf26817572e36f25e6c630 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Thu, 4 Feb 2010 23:00:34 +0200 Subject: [PATCH] * enforce that maildir paths are absolute --- man/mu.1 | 9 +++------ src/mu-cmd-index.c | 17 +++++++++++------ src/mu-index.c | 6 ++++++ src/mu-index.h | 6 +++--- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/man/mu.1 b/man/mu.1 index 830da7ea..8516c708 100644 --- a/man/mu.1 +++ b/man/mu.1 @@ -144,12 +144,9 @@ more), \fBmu index\fR will terminate immediately. .TP \fB\-m\fR, \fB\-\-maildir\fR=\fI\fR -starts searching at \fI\fR. By default, -\fBmu\fR uses whatever the -.B MAILDIR -environment variable is set to; if that is not set, it tries -.B ~/Maildir -\. +starts searching at \fI\fR. By default, \fBmu\fR uses whatever the +\fBMAILDIR\fR environment variable is set to; if that is not set, it tries +\fI~/Maildir\fR \. In either case, the path must be \fBabsolute\fR. .TP \fB\-r\fR, \fB\-\-reindex\fR diff --git a/src/mu-cmd-index.c b/src/mu-cmd-index.c index 1c17c27e..169fe92e 100644 --- a/src/mu-cmd-index.c +++ b/src/mu-cmd-index.c @@ -36,17 +36,17 @@ static gboolean MU_CAUGHT_SIGNAL; static void update_warning (void) { - g_warning ("the database needs to be updated to version %s", + g_warning ("Note: the database needs to be updated to version %s\n", MU_XAPIAN_DB_VERSION); - g_message ("please run 'mu index --empty' (see the manpage)"); + g_warning ("please run 'mu index --empty' (see the manpage)\n"); } static void sig_handler (int sig) { if (!MU_CAUGHT_SIGNAL && sig == SIGINT) /* Ctrl-C */ - g_message ("Shutting down gracefully, " - "press again to kill immediately"); + g_warning ("Shutting down gracefully, " + "press again to kill immediately\n"); MU_CAUGHT_SIGNAL = TRUE; } @@ -74,12 +74,17 @@ static gboolean check_index_params (MuConfigOptions *opts) { if (opts->linksdir || opts->xquery) { - g_warning ("Invalid option(s) for command"); + g_warning ("Error: Invalid option(s) for command\n"); + return FALSE; + } + + if (!g_path_is_absolute (opts->maildir)) { + g_warning ("Error: maildir path must be absolute\n"); return FALSE; } if (!mu_util_check_dir (opts->maildir, TRUE, FALSE)) { - g_message ("Please provide a valid Maildir"); + g_warning ("Error: not a valid Maildir\n"); return FALSE; } diff --git a/src/mu-index.c b/src/mu-index.c index 74e81de3..6ccd0869 100644 --- a/src/mu-index.c +++ b/src/mu-index.c @@ -222,6 +222,12 @@ static gboolean check_path (const char* path) { g_return_val_if_fail (path, FALSE); + + if (!g_path_is_absolute (path)) { + g_warning ("%s: not an absolute path: %s", + __FUNCTION__, path); + return FALSE; + } if (access (path, R_OK) != 0) { g_warning ("%s: cannot open '%s': %s", diff --git a/src/mu-index.h b/src/mu-index.h index 9686cd77..509353a9 100644 --- a/src/mu-index.h +++ b/src/mu-index.h @@ -90,7 +90,7 @@ typedef MuResult (*MuIndexDirCallback) (const char* path, gboolean enter, * start the indexing process * * @param index a valid MuIndex instance - * @param path the path to index + * @param path the path to index. This must be an absolute path * @param force if != 0, force re-indexing already index messages; this is * obviously a lot slower than only indexing new/changed messages * @param stats a structure with some statistics about the results; @@ -116,8 +116,8 @@ MuResult mu_index_run (MuIndex *index, const char* path, gboolean force, * mu_index_run sees, when there are updates in the Maildir * * @param index a valid MuIndex instance - * @param path the path to get stats for - * @param stats a structure with some statistics about the results; + * @param path the path to get stats for; this must be an absolute path + * @param stats a structure with some statistics about the results; * note that this function does *not* reset the struct values to allow * for cumulative stats from multiple calls. If needed, you can use * @mu_index_stats_clear before calling this function