gout

A static git page generator
git clone https://git.bracken.jp/gout.git
Log | Files | Refs | README | LICENSE

commit ae9f630c1303dfcf78e4a95185ecca52e7fb204a
parent ed304b815e7741c7cf2bc2b4cd3b79540f47d8a7
Author: Chris Bracken <chris@bracken.jp>
Date:   Thu, 19 Feb 2026 13:36:22 +0900

cache: if cache file is empty/corrupt do a full build

If the cache file exists but is empty or corrupt, we continue processing
with a full build as though there hadn't been a cache file at all. The
cache file is simply an optimisation so this isn't the end of the world.

Diffstat:
Msrc/writer/cache/cache.c | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/writer/cache/cache.c b/src/writer/cache/cache.c @@ -39,10 +39,17 @@ Cache* cache_create(const char* cache_path, WriteCommitRow write_func) { // OID + '\n' + '\0'. char buf[kOidLen + 1]; char* oid_str = fgets(buf, sizeof(buf), cache->cache_in); - if (!oid_str) { - err(1, "fgets"); + if (oid_str) { + // Copy oid_str and trim trailing newline if it exists. + estrlcpy(cache->lastoid_in, oid_str, kOidLen); + size_t len = strlen(cache->lastoid_in); + while (len > 0 && (cache->lastoid_in[len - 1] == '\n' || + cache->lastoid_in[len - 1] == '\r')) { + cache->lastoid_in[--len] = '\0'; + } + } else { + warnx("corrupt cachefile: %s", cache_path); } - estrlcpy(cache->lastoid_in, oid_str, sizeof(buf)); } cache->wrote_lastoid_out = false;