From 95c15b7a6af8e156a831daa5e87554dfea094ad3 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 4 Sep 2012 15:03:12 +0100 Subject: [PATCH 3/4] mcd_ensure_directory: add I keep calling g_mkdir_with_parents() and expecting it to return a boolean (it doesn't, it returns 0 or -1), so it seems worth wrapping it in something more sensible. Signed-off-by: Simon McVittie --- src/mcd-misc.c | 17 +++++++++++++++++ src/mcd-misc.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/mcd-misc.c b/src/mcd-misc.c index 294d2a7..c0cc4e1 100644 --- a/src/mcd-misc.c +++ b/src/mcd-misc.c @@ -176,6 +176,23 @@ _mcd_object_ready (gpointer object, GQuark quark, const GError *error) g_object_unref (object); } +gboolean +mcd_ensure_directory (const gchar *dir, + GError **error) +{ + DEBUG ("%s", dir); + + if (g_mkdir_with_parents (dir, 0700) != 0) + { + g_set_error (error, TP_ERROR, TP_ERROR_NOT_AVAILABLE, + "Unable to create directory '%s': %s", + dir, g_strerror (errno)); + return FALSE; + } + + return TRUE; +} + int _mcd_chmod_private (const gchar *filename) { diff --git a/src/mcd-misc.h b/src/mcd-misc.h index e69ee72..741a109 100644 --- a/src/mcd-misc.h +++ b/src/mcd-misc.h @@ -51,6 +51,8 @@ void _mcd_object_ready (gpointer object, GQuark quark, const GError *error); G_GNUC_INTERNAL void _mcd_ext_register_dbus_glib_marshallers (void); +gboolean mcd_ensure_directory (const gchar *dir, GError **error); + G_GNUC_INTERNAL int _mcd_chmod_private (const gchar *filename); G_END_DECLS -- 1.7.10.4