Refactor legacy code (#35708) (#35713)

Backport #35708
This commit is contained in:
wxiaoguang
2025-10-21 09:10:10 +08:00
committed by GitHub
parent 0a87bf9016
commit e818de179e
15 changed files with 407 additions and 236 deletions

View File

@@ -115,15 +115,10 @@ func IsDir(dir string) (bool, error) {
return false, err
}
// IsFile returns true if given path is a file,
// or returns false when it's a directory or does not exist.
func IsFile(filePath string) (bool, error) {
f, err := os.Stat(filePath)
func IsRegularFile(filePath string) (bool, error) {
f, err := os.Lstat(filePath)
if err == nil {
return !f.IsDir(), nil
}
if os.IsNotExist(err) {
return false, nil
return f.Mode().IsRegular(), nil
}
return false, err
}