journal: make current log file have a fixed named (#7112)

This commit is contained in:
Adrian Lanzafame 2021-08-26 18:48:28 +10:00 committed by GitHub
parent 7c484cae13
commit 15667db6a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -108,14 +108,28 @@ func (f *fsJournal) rollJournalFile() error {
if f.fi != nil {
_ = f.fi.Close()
}
current := filepath.Join(f.dir, "lotus-journal.ndjson")
rolled := filepath.Join(f.dir, fmt.Sprintf(
"lotus-journal-%s.ndjson",
build.Clock.Now().Format(RFC3339nocolon),
))
nfi, err := os.Create(filepath.Join(f.dir, fmt.Sprintf("lotus-journal-%s.ndjson", build.Clock.Now().Format(RFC3339nocolon))))
// check if journal file exists
if fi, err := os.Stat(current); err == nil && !fi.IsDir() {
err := os.Rename(current, rolled)
if err != nil {
return xerrors.Errorf("failed to open journal file: %w", err)
return xerrors.Errorf("failed to roll journal file: %w", err)
}
}
nfi, err := os.Create(current)
if err != nil {
return xerrors.Errorf("failed to create journal file: %w", err)
}
f.fi = nfi
f.fSize = 0
return nil
}