summaryrefslogtreecommitdiff
path: root/src/drun.c
diff options
context:
space:
mode:
authorPhil Jones <philj56@gmail.com>2024-12-30 11:16:37 +0000
committerPhil Jones <philj56@gmail.com>2024-12-30 11:17:05 +0000
commite2bed7eda881a4273f61742f38eaae6b71daf340 (patch)
tree0b70b39d8d4bc626a10e7f7d851ce19582134c99 /src/drun.c
parentb32c9954d3da430392575e9e637a2d8d114e34d0 (diff)
Handle `fopen()` errors with drun cache.
Diffstat (limited to 'src/drun.c')
-rw-r--r--src/drun.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/drun.c b/src/drun.c
index ad9b937..851fdd1 100644
--- a/src/drun.c
+++ b/src/drun.c
@@ -233,7 +233,13 @@ struct desktop_vec drun_generate_cached()
free(cache_path);
return apps;
}
+ errno = 0;
FILE *cache = fopen(cache_path, "wb");
+ if (cache == NULL) {
+ log_error("Error creating drun cache: %s.\n", strerror(errno));
+ free(cache_path);
+ return apps;
+ }
desktop_vec_save(&apps, cache);
fclose(cache);
free(cache_path);
@@ -265,14 +271,27 @@ struct desktop_vec drun_generate_cached()
log_indent();
apps = drun_generate();
log_unindent();
+ errno = 0;
FILE *cache = fopen(cache_path, "wb");
- desktop_vec_save(&apps, cache);
- fclose(cache);
+ if (cache == NULL) {
+ log_error("Failed to update cache: %s.\n", strerror(errno));
+ } else {
+ desktop_vec_save(&apps, cache);
+ fclose(cache);
+ }
} else {
log_debug("Cache up to date, loading.\n");
+ errno = 0;
FILE *cache = fopen(cache_path, "rb");
- apps = desktop_vec_load(cache);
- fclose(cache);
+ if (cache == NULL) {
+ log_error("Failed to load cache: %s.\n", strerror(errno));
+ log_indent();
+ apps = drun_generate();
+ log_unindent();
+ } else {
+ apps = desktop_vec_load(cache);
+ fclose(cache);
+ }
}
free(cache_path);
return apps;