fix: use os.ErrNotExist instead of errors.New() for file-not-found detection in checkers
errors.Is(err, errors.New("file does not exist")) can never match because
errors.New creates a unique value each time. Replace with os.ErrNotExist
which is the standard Go sentinel for file-not-found errors.
Fixes both mfer/checker.go and internal/checker/checker.go.
This commit is contained in:
@@ -174,12 +174,7 @@ func (c *Checker) checkFile(entry *mfer.MFFilePath, checkedBytes *int64) Result
|
||||
// Check if file exists
|
||||
info, err := c.fs.Stat(absPath)
|
||||
if err != nil {
|
||||
if errors.Is(err, afero.ErrFileNotFound) || errors.Is(err, errors.New("file does not exist")) {
|
||||
return Result{Path: entry.Path, Status: StatusMissing, Message: "file not found"}
|
||||
}
|
||||
// Check for "file does not exist" style errors
|
||||
exists, _ := afero.Exists(c.fs, absPath)
|
||||
if !exists {
|
||||
if errors.Is(err, os.ErrNotExist) || errors.Is(err, afero.ErrFileNotFound) {
|
||||
return Result{Path: entry.Path, Status: StatusMissing, Message: "file not found"}
|
||||
}
|
||||
return Result{Path: entry.Path, Status: StatusError, Message: err.Error()}
|
||||
|
||||
Reference in New Issue
Block a user