From 1b39ab0ba4e4ecad746c934bd89ba0938ff0e04d Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Thu, 20 Apr 2017 22:58:59 +0200 Subject: [PATCH] Show if directory can't be created. --- src/main.c | 4 ++++ src/util.c | 20 ++++++++++++++++---- src/util.h | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 7b0f4ba..85b3c53 100644 --- a/src/main.c +++ b/src/main.c @@ -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)) { diff --git a/src/util.c b/src/util.c index b392876..94d8fb1 100644 --- a/src/util.c +++ b/src/util.c @@ -18,6 +18,7 @@ */ #include +#include #include #include #include @@ -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; } /** diff --git a/src/util.h b/src/util.h index 63f5046..c1830a2 100644 --- a/src/util.h +++ b/src/util.h @@ -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, ...); -- 2.20.1