Show if directory can't be created.
authorDaniel Carl <danielcarl@gmx.de>
Thu, 20 Apr 2017 20:58:59 +0000 (22:58 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Thu, 20 Apr 2017 20:58:59 +0000 (22:58 +0200)
src/main.c
src/util.c
src/util.h

index 7b0f4ba..85b3c53 100644 (file)
@@ -126,6 +126,10 @@ gboolean vb_download_set_destination(Client *c, WebKitDownload *download,
         file = util_build_path(c, suggested_filename, download_path);
     }
 
+    if (!file) {
+        return FALSE;
+    }
+
     /* If the filepath exists already insert numerical suffix before file
      * extension. */
     if (g_file_test(file, G_FILE_TEST_EXISTS)) {
index b392876..94d8fb1 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include <ctype.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <glib.h>
 #include <JavaScriptCore/JavaScript.h>
@@ -71,9 +72,16 @@ char *util_build_path(Client *c, const char *path, const char *dir)
 
     /* Create the directory part of the path if it does not exists. */
     if ((p = strrchr(fullPath, '/'))) {
+        gboolean res;
         *p = '\0';
-        util_create_dir_if_not_exists(fullPath);
+        res = util_create_dir_if_not_exists(fullPath);
         *p = '/';
+
+        if (!res) {
+            g_free(fullPath);
+
+            return NULL;
+        }
     }
 
     return fullPath;
@@ -89,11 +97,15 @@ void util_cleanup(void)
     }
 }
 
-void util_create_dir_if_not_exists(const char *dirpath)
+gboolean util_create_dir_if_not_exists(const char *dirpath)
 {
-    if (!g_file_test(dirpath, G_FILE_TEST_IS_DIR)) {
-        g_mkdir_with_parents(dirpath, 0755);
+    if (!g_mkdir_with_parents(dirpath, 0755)) {
+        g_critical("Could not create directory '%s': %s", dirpath, strerror(errno));
+
+        return FALSE;
     }
+
+    return TRUE;
 }
 
 /**
index 63f5046..c1830a2 100644 (file)
@@ -32,7 +32,7 @@ typedef void *(*Util_Content_Func)(const char*, const char*);
 
 char *util_build_path(Client *c, const char *path, const char *dir);
 void util_cleanup(void);
-void util_create_dir_if_not_exists(const char *dirpath);
+gboolean util_create_dir_if_not_exists(const char *dirpath);
 char *util_expand(Client *c, const char *src, int expflags);
 gboolean util_file_append(const char *file, const char *format, ...);
 gboolean util_file_prepend(const char *file, const char *format, ...);