about summary refs log tree commit diff stats
path: root/src/common.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-08-04 17:20:46 +0100
committerJames Booth <boothj5@gmail.com>2013-08-04 17:20:46 +0100
commit3588a9d7761669f6d1c6776a07cc0555afd4b084 (patch)
tree7a1d204a8d2fcc4f3b0ac7f5278b978446c54ad5 /src/common.c
parent87c627710906171b3696e65fac985bd50c43c6f3 (diff)
parent20dff5fe2f0251d39a1667b547a49cef3b115899 (diff)
downloadprofani-tty-3588a9d7761669f6d1c6776a07cc0555afd4b084.tar.gz
Merge remote-tracking branch 'dmitry/nextdev-patches' into nextdev
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/common.c b/src/common.c
index e2ff0171..da33cc3d 100644
--- a/src/common.c
+++ b/src/common.c
@@ -25,12 +25,14 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/types.h>
 #include <sys/stat.h>
 
 #include <curl/curl.h>
 #include <curl/easy.h>
 #include <glib.h>
 
+#include "log.h"
 #include "common.h"
 
 // assume malloc stores at most 8 bytes for size of allocated memory
@@ -69,29 +71,43 @@ p_slist_free_full(GSList *items, GDestroyNotify free_func)
     g_slist_free (items);
 }
 
-void
+gboolean
 create_dir(char *name)
 {
-    int e;
     struct stat sb;
 
-    e = stat(name, &sb);
-    if (e != 0)
-        if (errno == ENOENT)
-            e = mkdir(name, S_IRWXU);
+    if (stat(name, &sb) != 0) {
+        if (errno != ENOENT || mkdir(name, S_IRWXU) != 0) {
+            return FALSE;
+        }
+    } else {
+        if ((sb.st_mode & S_IFDIR) != S_IFDIR) {
+            log_debug("create_dir: %s exists and is not a directory!", name);
+            return FALSE;
+        }
+    }
+
+    return TRUE;
 }
 
-void
+gboolean
 mkdir_recursive(const char *dir)
 {
     int i;
+    gboolean result = TRUE;
+
     for (i = 1; i <= strlen(dir); i++) {
         if (dir[i] == '/' || dir[i] == '\0') {
             gchar *next_dir = g_strndup(dir, i);
-            create_dir(next_dir);
+            result = create_dir(next_dir);
             g_free(next_dir);
+            if (!result) {
+                break;
+            }
         }
     }
+
+    return result;
 }
 
 char *