Rename files or directories inside the workspace.
(
src: Annotated[str, ParamMeta(description="Existing workspace-relative path")],
dst: Annotated[str, ParamMeta(description="New workspace-relative path")],
*,
overwrite: Annotated[
bool,
ParamMeta(description="Allow replacing an existing destination"),
] = False,
_context: Dict[str, Any] | None = None,
)
| 599 | |
| 600 | |
| 601 | def rename_path( |
| 602 | src: Annotated[str, ParamMeta(description="Existing workspace-relative path")], |
| 603 | dst: Annotated[str, ParamMeta(description="New workspace-relative path")], |
| 604 | *, |
| 605 | overwrite: Annotated[ |
| 606 | bool, |
| 607 | ParamMeta(description="Allow replacing an existing destination"), |
| 608 | ] = False, |
| 609 | _context: Dict[str, Any] | None = None, |
| 610 | ) -> Dict[str, Any]: |
| 611 | """Rename files or directories inside the workspace.""" |
| 612 | |
| 613 | ctx = FileToolContext(_context) |
| 614 | source = ctx.resolve_under_workspace(src) |
| 615 | destination = ctx.resolve_under_workspace(dst) |
| 616 | _check_attachments_not_modified(src) |
| 617 | _check_attachments_not_modified(dst) |
| 618 | |
| 619 | if not source.exists(): |
| 620 | raise FileNotFoundError(f"Source does not exist: {src}") |
| 621 | if source == destination: |
| 622 | return { |
| 623 | "path": ctx.to_workspace_relative(destination), |
| 624 | "operation": "rename", |
| 625 | "skipped": True, |
| 626 | } |
| 627 | |
| 628 | _clear_destination(destination, overwrite) |
| 629 | destination.parent.mkdir(parents=True, exist_ok=True) |
| 630 | source.rename(destination) |
| 631 | return { |
| 632 | "path": ctx.to_workspace_relative(destination), |
| 633 | "previous_path": ctx.to_workspace_relative(source), |
| 634 | "operation": "rename", |
| 635 | } |
| 636 | |
| 637 | |
| 638 | def copy_path( |
nothing calls this directly
no test coverage detected