MCPcopy Index your code
hub / github.com/bugy/script-server / _validate_recursive_path

Method _validate_recursive_path

src/model/parameter_config.py:459–493  ·  view source on GitHub ↗
(self, path, intermediate)

Source from the content-addressed store, hash-verified

457 return self.type == PARAM_TYPE_SERVER_FILE and self.file_recursive
458
459 def _validate_recursive_path(self, path, intermediate):
460 value_string = self.value_to_str(path)
461
462 if not isinstance(path, list):
463 return 'should be a list, but was: ' + value_string + '(' + str(type(path)) + ')'
464
465 if ('.' in path) or ('..' in path):
466 return 'Relative path references are not allowed'
467
468 full_path = self._build_list_file_path(path)
469
470 if self.excluded_files_matcher.has_match(full_path):
471 return 'Path ' + value_string + ' is excluded'
472
473 if not os.path.exists(full_path):
474 return 'Path ' + value_string + ' does not exist'
475
476 if intermediate:
477 if not os.access(full_path, os.R_OK):
478 return 'Path ' + value_string + ' not accessible'
479
480 if not os.path.isdir(full_path):
481 return 'Path ' + value_string + ' is not a directory'
482
483 else:
484 dir = path[:-1]
485 file = path[-1]
486
487 dir_path = self._build_list_file_path(dir)
488 allowed_files = model_helper.list_files(dir_path,
489 file_type=self.file_type,
490 file_extensions=self.file_extensions,
491 excluded_files_matcher=self.excluded_files_matcher)
492 if file not in allowed_files:
493 return 'Path ' + value_string + ' is not allowed'
494
495 def _build_list_file_path(self, child_path):
496 return os.path.normpath(os.path.join(self._list_files_dir, *child_path))

Callers 2

validate_valueMethod · 0.95
list_filesMethod · 0.95

Calls 4

value_to_strMethod · 0.95
_build_list_file_pathMethod · 0.95
list_filesMethod · 0.80
has_matchMethod · 0.45

Tested by

no test coverage detected