MCPcopy Create free account
hub / github.com/modelscope/ms-agent / get_real_path

Method get_real_path

ms_agent/tools/filesystem_tool.py:635–656  ·  view source on GitHub ↗
(self, path)

Source from the content-addressed store, hash-verified

633 return f'Replace lines in file <{path}> failed, error: ' + str(e)
634
635 def get_real_path(self, path):
636 # Check if path is absolute or already starts with output_dir
637 if os.path.isabs(path):
638 target_path = path
639 elif path.startswith(self.output_dir + os.sep) or path.startswith(
640 self.output_dir):
641 # Path already includes output_dir as prefix
642 target_path = path
643 else:
644 target_path = os.path.join(self.output_dir, path)
645 target_path_real = os.path.realpath(target_path)
646 output_dir_real = os.path.realpath(self.output_dir)
647 is_in_output_dir = target_path_real.startswith(
648 output_dir_real + os.sep) or target_path_real == output_dir_real
649
650 if not is_in_output_dir and not self.allow_read_all_files:
651 logger.warning(
652 f'Attempt to read file outside output directory blocked: {path} -> {target_path_real}'
653 )
654 return None
655 else:
656 return target_path_real
657
658 async def read_abbreviation_file(self, paths: list[str]):
659 results = {}

Callers 7

write_fileMethod · 0.95
replace_file_contentsMethod · 0.95
replace_file_linesMethod · 0.95
process_fileMethod · 0.95
read_fileMethod · 0.95
search_file_nameMethod · 0.95
search_file_contentMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected