From 0a0ba350750d8391ccac8fdb7e0745fe822421ab Mon Sep 17 00:00:00 2001 From: Scoopta Date: Fri, 28 Feb 2020 22:36:48 -0800 Subject: [PATCH] The cache directory will now be created if it doesn't already exist --- inc/utils.h | 5 +++++ src/utils.c | 9 +++++++++ src/wofi.c | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/inc/utils.h b/inc/utils.h index 5f9fca0..9d9894f 100644 --- a/inc/utils.h +++ b/inc/utils.h @@ -24,7 +24,10 @@ #include #include #include +#include +#include +#include #include time_t utils_get_time_millis(void); @@ -39,4 +42,6 @@ size_t utils_min3(size_t n1, size_t n2, size_t n3); size_t utils_distance(const char* haystack, const char* needle); +void utils_mkdir(char* path, mode_t mode); + #endif diff --git a/src/utils.c b/src/utils.c index 64eff1f..0faa717 100644 --- a/src/utils.c +++ b/src/utils.c @@ -97,3 +97,12 @@ size_t utils_distance(const char* haystack, const char* needle) { return arr[str1_len][str2_len]; } + +void utils_mkdir(char* path, mode_t mode) { + if(access(path, F_OK) != 0) { + char* tmp = strdup(path); + utils_mkdir(dirname(tmp), mode); + mkdir(path, mode); + free(tmp); + } +} diff --git a/src/wofi.c b/src/wofi.c index 058f74b..26f85c6 100644 --- a/src/wofi.c +++ b/src/wofi.c @@ -566,6 +566,11 @@ void wofi_write_cache(struct mode* mode, const char* _cmd) { char* cmd = escape_lf(_cmd); char* cache_path = get_cache_path(mode->name); + + char* tmp_dir = strdup(cache_path); + utils_mkdir(dirname(tmp_dir), S_IRWXU | S_IRGRP | S_IXGRP); + free(tmp_dir); + struct wl_list lines; wl_list_init(&lines); bool inc_count = false;