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

Function ValidateFile

util/util.go:317–340  ·  view source on GitHub ↗

Validate File

(afs afero.Fs, file string)

Source from the content-addressed store, hash-verified

315
316// Validate File
317func 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
343func validatePath(afs afero.Fs, path string) (bool, bool, bool, error) {

Callers 5

getCustomFeedFunction · 0.92
WalkFilesFunction · 0.92
ValidateConfigPathFunction · 0.92
TestValidateFileFunction · 0.85
GetFileContentsFunction · 0.85

Calls 1

validatePathFunction · 0.85

Tested by 1

TestValidateFileFunction · 0.68