From 7e68a85bfc975191a9cf2b6f6e17ee6bfc1b2e2c Mon Sep 17 00:00:00 2001 From: t_max <1172915550@qq.com> Date: Thu, 29 Aug 2024 18:18:03 +0800 Subject: [PATCH] fix: do not unlock the file when file locking fails --- rotatelogs.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rotatelogs.go b/rotatelogs.go index ecaf1c7..2003ae4 100644 --- a/rotatelogs.go +++ b/rotatelogs.go @@ -201,8 +201,8 @@ func (rl *RotateLogs) getWriterNolock(bailOnRotateFail, useGenerationalNames boo baseFn := fileutil.GenerateFn(rl.pattern, rl.clock, rl.rotationTime) var forceNewFile bool filename := baseFn - fi, err := os.Stat(rl.curFn) sizeRotation := false + fi, err := os.Stat(rl.curFn) if err == nil && rl.rotationSize > 0 && rl.rotationSize <= fi.Size() { forceNewFile = true sizeRotation = true @@ -332,7 +332,6 @@ func createLogFileAndLock(filename string, lockFilename string, appendFile bool) // check file in use err = LockFile(logFileHandle) if err != nil { - UnlockFile(logFileHandle) logFileHandle.Close() return nil, nil, err }