@@ -24,6 +24,9 @@ def copy_between_containers(
2424 """
2525 Copy files from one Docker container to another via a temporary local directory.
2626 """
27+ if Path (src_path ).is_dir ():
28+ src_path = f"{ src_path } /"
29+ dest_path = f"{ dest_path } /"
2730 with tempfile .TemporaryDirectory () as temp_dir :
2831 temp_path = Path (temp_dir ) / Path (src_path ).name
2932
@@ -32,9 +35,10 @@ def copy_between_containers(
3235 "docker" ,
3336 "cp" ,
3437 f"{ src_container .container_id } :{ src_path } " ,
35- str ( temp_path ) ,
38+ f" { temp_path } " ,
3639 ]
3740 result_src = subprocess .run (cmd_src , check = False , capture_output = True , text = True )
41+ print (result_src )
3842 if result_src .returncode != 0 :
3943 raise RuntimeError (
4044 f"Failed to copy from { src_container .container_id } to local temp: { result_src .stdout } { result_src .stderr } "
@@ -47,10 +51,11 @@ def copy_between_containers(
4751 cmd_dest = [
4852 "docker" ,
4953 "cp" ,
50- str ( temp_path ) ,
54+ f" { temp_path } " ,
5155 f"{ dest_container .container_id } :{ dest_path } " ,
5256 ]
5357 result_dest = subprocess .run (cmd_dest , check = False , capture_output = True , text = True )
58+ print (result_dest )
5459 if result_dest .returncode != 0 :
5560 raise RuntimeError (
5661 f"Failed to copy from local temp to { dest_container .container_id } : { result_dest .stdout } { result_dest .stderr } "
@@ -67,13 +72,17 @@ def copy_to_container(
6772
6873 The copy operation is recursive for directories.
6974 """
75+ # ALWAYS ADD TRAILING SLASHES EVERYWHERE
76+ if Path (src_path ).is_dir ():
77+ src_path = f"{ src_path } /"
78+ dest_path = f"{ dest_path } /"
7079 if not str (dest_path ).startswith ("/" ):
7180 # If not an absolute path, assume relative to container's cwd
72- dest_path = f"{ container .config .cwd } /{ dest_path } "
81+ dest_path = f"{ container .config .cwd } /{ dest_path } / "
7382 cmd = [
7483 "docker" ,
7584 "cp" ,
76- str ( src_path ) ,
85+ f" { src_path } " ,
7786 f"{ container .container_id } :{ dest_path } " ,
7887 ]
7988 # Ensure destination folder exists
@@ -96,11 +105,12 @@ def copy_from_container(
96105
97106 The copy operation is recursive for directories.
98107 """
108+ # ALWAYS ADD TRAILING SLASHES EVERYWHERE
99109 cmd = [
100110 "docker" ,
101111 "cp" ,
102112 f"{ container .container_id } :{ src_path } " ,
103- str ( dest_path ) ,
113+ f" { dest_path } /" ,
104114 ]
105115 Path (dest_path ).parent .mkdir (parents = True , exist_ok = True )
106116 result = subprocess .run (cmd , check = False , capture_output = True , text = True )
0 commit comments