Skip to content

Commit

Permalink
tweak handling of current log link
Browse files Browse the repository at this point in the history
  • Loading branch information
brianolson committed Nov 30, 2024
1 parent 716442a commit 7e4c6e5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion util/cliutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,21 @@ func (w *logRotateWriter) Write(p []byte) (n int, err error) {
dirpart, _ := filepath.Split(w.currentPath)
if dirpart != "" {
w.currentPathCurrent = filepath.Join(dirpart, "current")
fi, err := os.Stat(w.currentPathCurrent)
if err == nil && fi.Mode().IsRegular() {
// move aside unknown "current" from a previous run
err = os.Rename(w.currentPathCurrent, w.currentPathCurrent+"_"+nows)
if err != nil {
// not crucial if we can't move aside "current"
// TODO: log warning ... but not from inside log writer?
earlyWeakErrors = append(earlyWeakErrors, err)
}
}
err = os.Link(w.currentPath, w.currentPathCurrent)
if err != nil {
// not crucial if we can't make "current" link
// TODO: log warning ... but not from inside log writer?
earlyWeakErrors = append(earlyWeakErrors, err)
return 0, errors.Join(earlyWeakErrors...)
}
}
}
Expand Down

0 comments on commit 7e4c6e5

Please sign in to comment.