isRegular detects if the file exists and is not a symlink.
(to string)
| 369 | |
| 370 | // isRegular detects if the file exists and is not a symlink. |
| 371 | func isRegular(to string) (bool, error) { |
| 372 | fi, err := os.Lstat(to) |
| 373 | if err != nil { |
| 374 | if errors.Is(err, os.ErrNotExist) { |
| 375 | return false, nil |
| 376 | } |
| 377 | return false, xerrors.Errorf("lstat %s: %w", to, err) |
| 378 | } |
| 379 | |
| 380 | return fi.Mode().IsRegular(), nil |
| 381 | } |