Validate File
(afs afero.Fs, file string)
| 315 | |
| 316 | // Validate File |
| 317 | func ValidateFile(afs afero.Fs, file string) error { |
| 318 | // validate path |
| 319 | exists, isDir, empty, err := validatePath(afs, file) |
| 320 | if err != nil { |
| 321 | return err |
| 322 | } |
| 323 | |
| 324 | // check if file exists |
| 325 | if !exists { |
| 326 | return fmt.Errorf("%w: %s", ErrFileDoesNotExist, file) |
| 327 | } |
| 328 | |
| 329 | // check if path is a directory |
| 330 | if isDir { |
| 331 | return fmt.Errorf("%w: %s", ErrPathIsDir, file) |
| 332 | } |
| 333 | |
| 334 | // check if file is empty |
| 335 | if empty { |
| 336 | return fmt.Errorf("%w: %s", ErrFileIsEmtpy, file) |
| 337 | } |
| 338 | |
| 339 | return nil |
| 340 | } |
| 341 | |
| 342 | // validatePath validates a given path |
| 343 | func validatePath(afs afero.Fs, path string) (bool, bool, bool, error) { |