Caching now checks for an exact match, this prevents some weird edge cases when using search parsing

This commit is contained in:
Scoopta 2019-12-16 23:38:25 -08:00
parent 8594fc52a3
commit 0458f06afe

View File

@ -342,17 +342,36 @@ void wofi_write_cache(const gchar* mode, const gchar* cmd) {
char* line = NULL; char* line = NULL;
size_t size = 0; size_t size = 0;
while(getline(&line, &size, file) != -1) { while(getline(&line, &size, file) != -1) {
struct cache_line* node = malloc(sizeof(struct cache_line)); char* space = strchr(line, ' ');
if(strstr(line, cmd) != NULL) { char* nl = strchr(line, '\n');
if(nl != NULL) {
*nl = 0;
}
if(space != NULL && strcmp(cmd, space + 1) == 0) {
struct cache_line* node = malloc(sizeof(struct cache_line));
uint64_t count = strtol(line, NULL, 10) + 1; uint64_t count = strtol(line, NULL, 10) + 1;
char num[6]; char num[6];
snprintf(num, 5, "%" PRIu64, count); snprintf(num, 5, "%" PRIu64, count);
node->line = utils_concat(4, num, " ", cmd, "\n"); node->line = utils_concat(4, num, " ", cmd, "\n");
inc_count = true; inc_count = true;
} else { wl_list_insert(&lines, &node->link);
node->line = strdup(line); }
}
free(line);
line = NULL;
size = 0;
fseek(file, 0, SEEK_SET);
while(getline(&line, &size, file) != -1) {
char* space = strchr(line, ' ');
char* nl = strchr(line, '\n');
if(nl != NULL) {
*nl = 0;
}
if(space == NULL || strcmp(cmd, space + 1) != 0) {
struct cache_line* node = malloc(sizeof(struct cache_line));
node->line = utils_concat(2, line, "\n");
wl_list_insert(&lines, &node->link);
} }
wl_list_insert(&lines, &node->link);
} }
free(line); free(line);
fclose(file); fclose(file);