From 7e4c6e5dca837f6b0352056cdda3d36a9aa5162d Mon Sep 17 00:00:00 2001 From: Brian Olson Date: Sat, 30 Nov 2024 12:55:38 -0500 Subject: [PATCH] tweak handling of current log link --- util/cliutil/util.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/util/cliutil/util.go b/util/cliutil/util.go index adeb378d1..6070b3f0d 100644 --- a/util/cliutil/util.go +++ b/util/cliutil/util.go @@ -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...) } } }