Fixed cache files not being auto-created
This commit is contained in:
parent
e5300b2995
commit
f60cdc0167
@ -26,6 +26,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
19
src/wofi.c
19
src/wofi.c
@ -411,7 +411,7 @@ void wofi_write_cache(const gchar* mode, const gchar* cmd) {
|
|||||||
struct wl_list lines;
|
struct wl_list lines;
|
||||||
wl_list_init(&lines);
|
wl_list_init(&lines);
|
||||||
bool inc_count = false;
|
bool inc_count = false;
|
||||||
if(access(cache_path, R_OK | W_OK) == 0) {
|
if(access(cache_path, R_OK) == 0) {
|
||||||
FILE* file = fopen(cache_path, "r");
|
FILE* file = fopen(cache_path, "r");
|
||||||
char* line = NULL;
|
char* line = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
@ -449,14 +449,18 @@ void wofi_write_cache(const gchar* mode, const gchar* cmd) {
|
|||||||
}
|
}
|
||||||
free(line);
|
free(line);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
}
|
||||||
|
if(!inc_count) {
|
||||||
|
struct cache_line* node = malloc(sizeof(struct cache_line));
|
||||||
|
node->line = utils_concat(3, "1 ", cmd, "\n");
|
||||||
|
wl_list_insert(&lines, &node->link);
|
||||||
|
}
|
||||||
|
|
||||||
if(!inc_count) {
|
char* tmp_path = strdup(cache_path);
|
||||||
struct cache_line* node = malloc(sizeof(struct cache_line));
|
char* dir = dirname(tmp_path);
|
||||||
node->line = utils_concat(3, "1 ", cmd, "\n");
|
|
||||||
wl_list_insert(&lines, &node->link);
|
|
||||||
}
|
|
||||||
|
|
||||||
file = fopen(cache_path, "w");
|
if(access(dir, W_OK) == 0) {
|
||||||
|
FILE* file = fopen(cache_path, "w");
|
||||||
struct cache_line* node, *tmp;
|
struct cache_line* node, *tmp;
|
||||||
wl_list_for_each_safe(node, tmp, &lines, link) {
|
wl_list_for_each_safe(node, tmp, &lines, link) {
|
||||||
fwrite(node->line, 1, strlen(node->line), file);
|
fwrite(node->line, 1, strlen(node->line), file);
|
||||||
@ -468,6 +472,7 @@ void wofi_write_cache(const gchar* mode, const gchar* cmd) {
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
free(cache_path);
|
free(cache_path);
|
||||||
|
free(tmp_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wofi_remove_cache(const gchar* mode, const gchar* cmd) {
|
void wofi_remove_cache(const gchar* mode, const gchar* cmd) {
|
||||||
|
Loading…
Reference in New Issue
Block a user