The cache directory will now be created if it doesn't already exist

This commit is contained in:
Scoopta 2020-02-28 22:36:48 -08:00
parent 0dec3c883d
commit 0a0ba35075
3 changed files with 19 additions and 0 deletions

View File

@ -24,7 +24,10 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <libgen.h>
#include <sys/stat.h>
#include <sys/time.h> #include <sys/time.h>
time_t utils_get_time_millis(void); 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); size_t utils_distance(const char* haystack, const char* needle);
void utils_mkdir(char* path, mode_t mode);
#endif #endif

View File

@ -97,3 +97,12 @@ size_t utils_distance(const char* haystack, const char* needle) {
return arr[str1_len][str2_len]; 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);
}
}

View File

@ -566,6 +566,11 @@ void wofi_write_cache(struct mode* mode, const char* _cmd) {
char* cmd = escape_lf(_cmd); char* cmd = escape_lf(_cmd);
char* cache_path = get_cache_path(mode->name); 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; struct wl_list lines;
wl_list_init(&lines); wl_list_init(&lines);
bool inc_count = false; bool inc_count = false;