much improved functions for maknig directories, props to Logan
authorDana Jansens <danakj@orodu.net>
Sat, 25 Oct 2003 19:13:09 +0000 (19:13 +0000)
committerDana Jansens <danakj@orodu.net>
Sat, 25 Oct 2003 19:13:09 +0000 (19:13 +0000)
openbox/session.c
parser/parse.c
parser/parse.h

index 8e8f2b7..cedd364 100644 (file)
@@ -163,7 +163,9 @@ void session_startup(gint *argc, gchar ***argv)
 
     sm_sessions_path = g_build_filename(parse_xdg_data_home_path(),
                                         "openbox", "sessions", NULL);
-    parse_mkdir_path(sm_sessions_path, 0700);
+    if (!parse_mkdir_path(sm_sessions_path, 0700))
+        g_warning(_("unable to make directory '%s': %s"),
+                  sm_sessions_path, g_strerror(errno));
 
     if (save_file)
         session_load(save_file);
index 69343a8..f7ca9d7 100644 (file)
@@ -19,6 +19,7 @@
 #include "parse.h"
 #include <glib.h>
 #include <string.h>
+#include <errno.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 
@@ -386,21 +387,45 @@ gchar *parse_expand_tilde(const gchar *f)
     return ret;
 }
 
-void parse_mkdir_path(const gchar *path, gint mode)
+gboolean parse_mkdir(const gchar *path, gint mode)
 {
-    gchar *c, *e;
+    gboolean ret = TRUE;
 
-    g_assert(path[0] == '/');
+    g_return_val_if_fail(path != NULL, FALSE);
+    g_return_val_if_fail(path[0] != '\0', FALSE);
 
-    c = g_strdup(path);
-    e = c;
-    while ((e = strchr(e + 1, '/'))) {
-        *e = '\0';
-        mkdir(c, mode);
-        *e = '/';
+    if (!g_file_test(path, G_FILE_TEST_IS_DIR))
+        if (mkdir(path, mode) == -1)
+            ret = FALSE;
+
+    return ret;
+}
+
+gboolean parse_mkdir_path(const gchar *path, gint mode)
+{
+    gboolean ret = TRUE;
+
+    g_return_val_if_fail(path != NULL, FALSE);
+    g_return_val_if_fail(path[0] == '/', FALSE);
+
+    if (!g_file_test(path, G_FILE_TEST_IS_DIR)) {
+        gchar *c, *e;
+
+        c = g_strdup(path);
+        e = c;
+        while ((e = strchr(e + 1, '/'))) {
+            *e = '\0';
+            if (!(ret = parse_mkdir(c, mode)))
+                goto parse_mkdir_path_end;
+            *e = '/';
+        }
+        ret = parse_mkdir(c, mode);
+
+    parse_mkdir_path_end:
+        g_free(c);
     }
-    mkdir(c, mode);
-    g_free(c);
+
+    return ret;
 }
 
 const gchar* parse_xdg_config_home_path()
index 886b867..9978011 100644 (file)
@@ -79,8 +79,10 @@ GSList* parse_xdg_data_dir_paths();
 /*! Expands the ~ character to the home directory throughout the given
   string */
 gchar *parse_expand_tilde(const gchar *f);
+/*! Makes a directory */
+gboolean parse_mkdir(const gchar *path, gint mode);
 /*! Makes a directory and all its parents */
-void parse_mkdir_path(const gchar *path, gint mode);
+gboolean parse_mkdir_path(const gchar *path, gint mode);
 
 G_END_DECLS