From 2999e5d1f151ff579c688cb734e871026eefca22 Mon Sep 17 00:00:00 2001
From: ysicing <i@ysicing.me>
Date: Mon, 18 Dec 2023 10:08:10 +0800
Subject: [PATCH] refactor: improve file condition and add prefix check in file
 handling

- In `file.go`, the condition `if !fi.IsDir()` was changed to `if fi != nil && !fi.IsDir()`
- The check `strings.HasPrefix(filepath.Base(path), filepath.Base(l.filename))` was added to the same if statement in `file.go`

Signed-off-by: ysicing <i@ysicing.me>
---
 file.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/file.go b/file.go
index 25c05f3..fbd1d55 100644
--- a/file.go
+++ b/file.go
@@ -101,7 +101,7 @@ func rotateFilename(filename, date string) string {
 
 func (l *fileLogger) deleteOutdatedFiles() error {
 	return filepath.Walk(filepath.Dir(l.filename), func(path string, fi os.FileInfo, _ error) error {
-		if !fi.IsDir() &&
+		if fi != nil && !fi.IsDir() &&
 			fi.ModTime().Before(time.Now().Add(-24*time.Hour*time.Duration(l.rotationConfig.MaxDays))) &&
 			strings.HasPrefix(filepath.Base(path), filepath.Base(l.filename)) {
 			return os.Remove(path)