common: simplify FileExist helper #32969 (#1871)

This commit is contained in:
wit liu 2025-12-19 15:07:32 +08:00 committed by GitHub
parent b3d12e4fda
commit 75f147a362
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -17,6 +17,8 @@
package common
import (
"errors"
"io/fs"
"os"
"path/filepath"
)
@ -24,11 +26,7 @@ import (
// FileExist checks if a file exists at filePath.
func FileExist(filePath string) bool {
_, err := os.Stat(filePath)
if err != nil && os.IsNotExist(err) {
return false
}
return true
return !errors.Is(err, fs.ErrNotExist)
}
// AbsolutePath returns datadir + filename, or filename if it is absolute.