validatePath validates a given path
(afs afero.Fs, path string)
| 341 | |
| 342 | // validatePath validates a given path |
| 343 | func validatePath(afs afero.Fs, path string) (bool, bool, bool, error) { |
| 344 | var exists, isDir, empty bool |
| 345 | |
| 346 | // validate parameters |
| 347 | if afs == nil { |
| 348 | return exists, isDir, empty, ErrFileSystemIsNil |
| 349 | } |
| 350 | if path == "" { |
| 351 | return exists, isDir, empty, ErrInvalidPath |
| 352 | } |
| 353 | |
| 354 | // check if path exists |
| 355 | exists, err := pathExists(afs, path) |
| 356 | if err != nil { |
| 357 | return exists, isDir, empty, err |
| 358 | } |
| 359 | |
| 360 | if exists { |
| 361 | // check if path is a directory |
| 362 | isDir, err = isDirectory(afs, path) |
| 363 | if err != nil { |
| 364 | return exists, isDir, empty, err |
| 365 | } |
| 366 | |
| 367 | // check if directory is empty |
| 368 | empty, err = isEmpty(afs, path) |
| 369 | if err != nil { |
| 370 | return exists, isDir, empty, err |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | return exists, isDir, empty, nil |
| 375 | } |
| 376 | |
| 377 | // GetFileContents reads the contents of a file at the specified path |
| 378 | func GetFileContents(afs afero.Fs, path string) ([]byte, error) { |
no outgoing calls