parseExistingFilePath checks if the provided path points to an existing file and returns the path if valid.
(env string)
| 305 | |
| 306 | // parseExistingFilePath checks if the provided path points to an existing file and returns the path if valid. |
| 307 | func parseExistingFilePath(env string) (string, error) { |
| 308 | if env == "" { |
| 309 | return "", nil |
| 310 | } |
| 311 | |
| 312 | info, err := os.Stat(env) |
| 313 | if err != nil { |
| 314 | return "", fmt.Errorf("cannot access file %s: %w", env, err) |
| 315 | } |
| 316 | |
| 317 | if info.IsDir() { |
| 318 | return "", fmt.Errorf("%s is a directory, expected a file", env) |
| 319 | } |
| 320 | |
| 321 | return env, nil |
| 322 | } |