* add mode_t arg to mu_util_create_dir_maybe, add mu_util_cache_dir

This commit is contained in:
Dirk-Jan C. Binnema 2011-01-11 00:44:03 +02:00
parent 8eafb2b10a
commit a778d233c0
4 changed files with 26 additions and 17 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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)
{

View File

@ -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-<userid>/
*
* @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