From 08869718cf9ad51035fdc154adb861a224c0124e Mon Sep 17 00:00:00 2001 From: Plieg Date: Mon, 8 Jun 2026 19:07:22 +0200 Subject: [PATCH] fix: treat unconfirmed cache dir-fsync as a warning, not a save failure atomicfile now returns *WriteError{PhaseDirSync} when the parent-directory fsync fails after a successful rename. cache.json is reconstructible (it is rebuilt from Plex on the next run), so a durability-only failure should not fail the cache write. SaveTo now logs a warning and returns nil on PhaseDirSync, while still propagating genuine write failures. Depends on atomicfile v1.1.0 (PhaseDirSync). CI is red until Renovate bumps the atomicfile dependency after that release; merge only after the bump lands. --- internal/cache/cache.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/cache/cache.go b/internal/cache/cache.go index 48300bd..55a439b 100644 --- a/internal/cache/cache.go +++ b/internal/cache/cache.go @@ -121,7 +121,18 @@ func (c *Cache) SaveTo(path string) error { } if err := atomicfile.WriteFile(context.Background(), path, data, atomicfile.WithMode(0o600)); err != nil { - return err + // cache.json is reconstructible: a parent-dir fsync failure + // (PhaseDirSync) means the cache was written to disk but its + // durability across an immediate crash is not guaranteed. Don't + // fail the save for that — the data is present and would be rebuilt + // from Plex on the next run anyway. Surface it as a warning instead. + var we *atomicfile.WriteError + if errors.As(err, &we) && we.Phase == atomicfile.PhaseDirSync { + slog.Warn("cache written but parent-dir fsync unconfirmed; not guaranteed durable across an immediate crash", + "path", path, "error", err) + } else { + return err + } } slog.Debug("cache saved", "path", path, "bytes", len(data)) return nil