From 785a09ef7684050a6ac4ed057c1ae7f763256c8f Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Tue, 9 Aug 2011 07:53:50 +0300 Subject: [PATCH] * make mu_util_create_dir_maybe potentially not warn (useful when the logging system is not initialized yet) --- src/mu-util.c | 13 ++++++++----- src/mu-util.h | 7 +++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/mu-util.c b/src/mu-util.c index 25ece159..2fc285a4 100644 --- a/src/mu-util.c +++ b/src/mu-util.c @@ -128,7 +128,7 @@ mu_util_create_tmpdir (void) G_DIR_SEPARATOR, (int)random()*getpid()*(int)time(NULL)); - if (!mu_util_create_dir_maybe (dirname, 0700)) { + if (!mu_util_create_dir_maybe (dirname, 0700, FALSE)) { g_free (dirname); return NULL; } @@ -237,7 +237,7 @@ mu_util_guess_mu_homedir (void) } gboolean -mu_util_create_dir_maybe (const gchar *path, mode_t mode) +mu_util_create_dir_maybe (const gchar *path, mode_t mode, gboolean nowarn) { struct stat statbuf; @@ -247,14 +247,17 @@ mu_util_create_dir_maybe (const gchar *path, mode_t mode) if (stat (path, &statbuf) == 0) { if ((!S_ISDIR(statbuf.st_mode)) || (access (path, W_OK|R_OK) != 0)) { - g_warning ("not a read-writable directory: %s", path); + if (!nowarn) + g_warning ("not a read-writable" + "directory: %s", path); return FALSE; } } if (g_mkdir_with_parents (path, mode) != 0) { - g_warning ("failed to create %s: %s", - path, strerror(errno)); + if (!nowarn) + g_warning ("failed to create %s: %s", + path, strerror(errno)); return FALSE; } diff --git a/src/mu-util.h b/src/mu-util.h index f40e4800..c09f3610 100644 --- a/src/mu-util.h +++ b/src/mu-util.h @@ -75,12 +75,14 @@ gchar* mu_util_guess_mu_homedir (void) * if path exists, check that's a read/writeable dir; otherwise try to * create it (with perms 0700) * - * @param path path to the dir + * @param path path to the dir + * @param mode to set for the dir (as per chmod(1)) + * @param nowarn, if TRUE, don't write warnings (if any) to stderr * * @return TRUE if a read/writeable directory `path' exists after * leaving this function, FALSE otherwise */ -gboolean mu_util_create_dir_maybe (const gchar *path, mode_t mode) +gboolean mu_util_create_dir_maybe (const gchar *path, mode_t mode, gboolean nowarn) G_GNUC_WARN_UNUSED_RESULT; /** @@ -408,6 +410,7 @@ enum _MuExitCode { }; typedef enum _MuExitCode MuExitCode; + enum _MuError { MU_ERROR_XAPIAN, /* general xapian related error */ MU_ERROR_XAPIAN_CANNOT_GET_WRITELOCK, /* can't get write lock */