MCPcopy Create free account
hub / github.com/CodeClash-ai/CodeClash / copy_to_container

Function copy_to_container

codeclash/utils/environment.py:102–132  ·  view source on GitHub ↗

Copy a file or directory from the local filesystem to a Docker container. The copy operation is recursive for directories. Be extremely careful with trailing slashes in src_path and dest_path, the behavior of docker cp is also different depending on whether the destination exists.

(
    container: DockerEnvironment,
    src_path: str | Path,
    dest_path: str | Path,
)

Source from the content-addressed store, hash-verified

100 excluded_path.unlink()
101
102 # Ensure destination folder exists
103 assert_zero_exit_code(dest_container.execute(f"mkdir -p {Path(dest_path).parent}"))
104
105 # Copy from temporary local directory to destination container
106 cmd_dest = [
107 "docker",
108 "cp",
109 str(temp_path),
110 f"{dest_container.container_id}:{dest_path}",
111 ]
112 result_dest = subprocess.run(cmd_dest, check=False, capture_output=True, text=True)
113 if result_dest.returncode != 0:
114 raise RuntimeError(
115 f"Failed to copy from local temp to {dest_container.container_id}: {result_dest.stdout}{result_dest.stderr}"
116 )
117
118
119def copy_to_container(
120 container: DockerEnvironment,
121 src_path: str | Path,
122 dest_path: str | Path,
123):
124 """
125 Copy a file or directory from the local filesystem to a Docker container.
126
127 The copy operation is recursive for directories.
128
129 Be extremely careful with trailing slashes in src_path and dest_path, the behavior
130 of docker cp is also different depending on whether the destination exists.
131 """
132 if not str(dest_path).startswith("/"):
133 # If not an absolute path, assume relative to container's cwd
134 dest_path = f"{container.config.cwd}/{dest_path}"
135 cmd = [

Callers 4

runMethod · 0.90
run_edit_phaseMethod · 0.90
run_training_roundMethod · 0.90
create_file_in_containerFunction · 0.85

Calls 3

assert_zero_exit_codeFunction · 0.85
executeMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected