From a778d233c0d6c983fe789be4f2ae5c8b18bacb42 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Tue, 11 Jan 2011 00:44:03 +0200 Subject: [PATCH] * add mode_t arg to mu_util_create_dir_maybe, add mu_util_cache_dir --- src/mu-log.c | 2 +- src/mu-runtime.c | 2 +- src/mu-util.c | 19 ++++++++++++++++--- src/mu-util.h | 20 ++++++++------------ 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/mu-log.c b/src/mu-log.c index c76e487a..8854a0fc 100644 --- a/src/mu-log.c +++ b/src/mu-log.c @@ -174,7 +174,7 @@ mu_log_init (const char* muhome, g_return_val_if_fail (!MU_LOG, FALSE); g_return_val_if_fail (muhome, FALSE); - if (!mu_util_create_dir_maybe(muhome)) { + if (!mu_util_create_dir_maybe(muhome, 0700)) { g_warning ("failed to init log in %s", muhome); return FALSE; } diff --git a/src/mu-runtime.c b/src/mu-runtime.c index 5f6d282b..5f8fa64a 100644 --- a/src/mu-runtime.c +++ b/src/mu-runtime.c @@ -52,7 +52,7 @@ static void runtime_free (void); static gboolean mu_dir_is_readable_and_writable (const char* muhome) { - if (mu_util_create_dir_maybe (muhome)) + if (mu_util_create_dir_maybe (muhome, 0700)) return TRUE; g_warning ("cannot use '%s' as a mu homedir", muhome); diff --git a/src/mu-util.c b/src/mu-util.c index 4008e2c5..9fae4ad2 100644 --- a/src/mu-util.c +++ b/src/mu-util.c @@ -122,7 +122,7 @@ mu_util_create_tmpdir (void) G_DIR_SEPARATOR, (int)random()*getpid()*(int)time(NULL)); - if (!mu_util_create_dir_maybe (dirname)) { + if (!mu_util_create_dir_maybe (dirname, 0700)) { g_free (dirname); return NULL; } @@ -131,6 +131,18 @@ mu_util_create_tmpdir (void) } +const char* +mu_util_cache_dir (void) +{ + static char cachedir [PATH_MAX]; + + snprintf (cachedir, sizeof(cachedir), "%s%cmu-%u", + g_get_tmp_dir(), G_DIR_SEPARATOR, + getuid()); + + return cachedir; +} + gboolean mu_util_init_system (void) @@ -219,7 +231,7 @@ mu_util_guess_mu_homedir (void) } gboolean -mu_util_create_dir_maybe (const gchar *path) +mu_util_create_dir_maybe (const gchar *path, mode_t mode) { struct stat statbuf; @@ -234,7 +246,7 @@ mu_util_create_dir_maybe (const gchar *path) } } - if (g_mkdir_with_parents (path, 0700) != 0) { + if (g_mkdir_with_parents (path, mode) != 0) { g_warning ("failed to create %s: %s", path, strerror(errno)); return FALSE; @@ -289,6 +301,7 @@ mu_util_create_writeable_fd (const char* path, mode_t mode, return fd; } + gboolean mu_util_play (const char *path) { diff --git a/src/mu-util.h b/src/mu-util.h index 6b72e0d7..1978bb80 100644 --- a/src/mu-util.h +++ b/src/mu-util.h @@ -77,20 +77,9 @@ gchar* mu_util_guess_mu_homedir (void) * @return TRUE if a read/writeable directory `path' exists after * leaving this function, FALSE otherwise */ -gboolean mu_util_create_dir_maybe (const gchar *path) +gboolean mu_util_create_dir_maybe (const gchar *path, mode_t mode) G_GNUC_WARN_UNUSED_RESULT; - -/** - * create a temporary dir (typically, in /tmp) with a unique name, - * such that files can be saved there. - * - * @return the name of the new dir, or NULL in case of error. Free with g_free - */ -char* mu_util_create_tmpdir (void) - G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; - - /** * check whether path is a directory, and optionally, if it's readable * and/or writeable @@ -106,6 +95,13 @@ gboolean mu_util_check_dir (const gchar* path, gboolean readable, G_GNUC_WARN_UNUSED_RESULT; +/** + * get our the cache directory, typically, /tmp/mu-/ + * + * @return the cache directory; don't free + */ +const char* mu_util_cache_dir (void) G_GNUC_CONST; + /** * create a writeable file and return its file descriptor (which