more
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"errors"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -144,6 +145,12 @@ func (o *Outbox) compact() error {
|
||||
if err := os.Rename(tmp, o.path); err != nil {
|
||||
return err
|
||||
}
|
||||
// fsync the directory so the rename (the file swap) is itself durable — a
|
||||
// crash right after must not leave the pending log lost or a stale .tmp.
|
||||
if d, derr := os.Open(filepath.Dir(o.path)); derr == nil {
|
||||
_ = d.Sync()
|
||||
_ = d.Close()
|
||||
}
|
||||
o.f, err = os.OpenFile(o.path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user