From 516fd29da423432ef6dfded21a984f1d15dcab1a Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Mon, 5 Oct 2026 17:31:50 -0400 Subject: fix: slop casino and economy fixes --- internal/persistence/txn.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'internal/persistence') diff --git a/internal/persistence/txn.go b/internal/persistence/txn.go index 1049077..a12e227 100644 --- a/internal/persistence/txn.go +++ b/internal/persistence/txn.go @@ -406,7 +406,16 @@ func Recover(journalDir string) error { return err } for _, e := range entries { - if e.IsDir() || !hasSuffix(e.Name(), ".json") { + if e.IsDir() { + continue + } + if hasPrefix(e.Name(), ".save-") { + // A crash during a journal write leaves an atomic-writer temp + // behind; it is never a valid journal, so sweep it. + os.Remove(filepath.Join(journalDir, e.Name())) + continue + } + if !hasSuffix(e.Name(), ".json") { continue } path := filepath.Join(journalDir, e.Name()) @@ -445,6 +454,10 @@ func hasSuffix(s, suffix string) bool { return len(s) >= len(suffix) && s[len(s)-len(suffix):] == suffix } +func hasPrefix(s, prefix string) bool { + return len(s) >= len(prefix) && s[:len(prefix)] == prefix +} + // ListJournalFiles is a debugging helper: returns sorted journal file names. func ListJournalFiles(journalDir string) ([]string, error) { entries, err := os.ReadDir(journalDir) -- cgit v1.2.3