Copy a file tree within the workspace.
(
src: Annotated[str, ParamMeta(description="Source workspace-relative path")],
dst: Annotated[str, ParamMeta(description="Destination workspace-relative path")],
*,
overwrite: Annotated[
bool,
ParamMeta(description="Allow replacing destination if it exists"),
] = False,
_context: Dict[str, Any] | None = None,
)
| 636 | |
| 637 | |
| 638 | def copy_path( |
| 639 | src: Annotated[str, ParamMeta(description="Source workspace-relative path")], |
| 640 | dst: Annotated[str, ParamMeta(description="Destination workspace-relative path")], |
| 641 | *, |
| 642 | overwrite: Annotated[ |
| 643 | bool, |
| 644 | ParamMeta(description="Allow replacing destination if it exists"), |
| 645 | ] = False, |
| 646 | _context: Dict[str, Any] | None = None, |
| 647 | ) -> Dict[str, Any]: |
| 648 | """Copy a file tree within the workspace.""" |
| 649 | |
| 650 | ctx = FileToolContext(_context) |
| 651 | source = ctx.resolve_under_workspace(src) |
| 652 | destination = ctx.resolve_under_workspace(dst) |
| 653 | _check_attachments_not_modified(dst) |
| 654 | |
| 655 | if not source.exists(): |
| 656 | raise FileNotFoundError(f"Source does not exist: {src}") |
| 657 | if destination.exists(): |
| 658 | if not overwrite: |
| 659 | raise FileExistsError(f"Destination already exists: {dst}") |
| 660 | _clear_destination(destination, overwrite=True) |
| 661 | |
| 662 | destination.parent.mkdir(parents=True, exist_ok=True) |
| 663 | if source.is_dir(): |
| 664 | shutil.copytree(source, destination) |
| 665 | else: |
| 666 | shutil.copy2(source, destination) |
| 667 | return { |
| 668 | "path": ctx.to_workspace_relative(destination), |
| 669 | "source": ctx.to_workspace_relative(source), |
| 670 | "operation": "copy", |
| 671 | } |
| 672 | |
| 673 | |
| 674 | def move_path( |
nothing calls this directly
no test coverage detected