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)) {
*/
#include <ctype.h>
+#include <errno.h>
#include <fcntl.h>
#include <glib.h>
#include <JavaScriptCore/JavaScript.h>
/* 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;
}
}
-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;
}
/**
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, ...);