diff options
Diffstat (limited to 'internal/persistence')
| -rw-r--r-- | internal/persistence/txn.go | 15 |
1 files changed, 14 insertions, 1 deletions
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) |
