From b9fb42a4d0f20c700d9b932d20abfd371b80015d Mon Sep 17 00:00:00 2001 From: ne-sachirou Date: Thu, 22 Feb 2024 19:29:32 +0900 Subject: [PATCH] Reduce check-log errors when a file in the log directory has been removed at the moment of running check-log --- check-log/lib/check-log.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/check-log/lib/check-log.go b/check-log/lib/check-log.go index ffb0f0f1..743cdab9 100644 --- a/check-log/lib/check-log.go +++ b/check-log/lib/check-log.go @@ -6,6 +6,7 @@ import ( "context" "crypto/md5" "encoding/json" + "errors" "fmt" "io" "log" @@ -564,20 +565,21 @@ func saveState(f string, state *state) error { var errFileNotFoundByInode = fmt.Errorf("old file not found") func findFileByInode(inode uint, dir string) (string, error) { - entries, err := os.ReadDir(dir) - if err != nil { - return "", err - } + entries, readDirErr := os.ReadDir(dir) for _, entry := range entries { fi, err := entry.Info() - if err != nil { + if err != nil && !errors.Is(err, os.ErrNotExist) { return "", err } if detectInode(fi) == inode { return filepath.Join(dir, fi.Name()), nil } } - return "", errFileNotFoundByInode + err := errFileNotFoundByInode + if readDirErr != nil { + err = errors.Join(err, readDirErr) + } + return "", err } func openOldFile(f string, state *state) (*os.File, error) {