MCPcopy Create free account
hub / github.com/activecm/rita / validatePath

Function validatePath

util/util.go:343–375  ·  view source on GitHub ↗

validatePath validates a given path

(afs afero.Fs, path string)

Source from the content-addressed store, hash-verified

341
342// validatePath validates a given path
343func 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
378func GetFileContents(afs afero.Fs, path string) ([]byte, error) {

Callers 3

TestValidatePathFunction · 0.85
ValidateDirectoryFunction · 0.85
ValidateFileFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestValidatePathFunction · 0.68