|
5 | 5 | import os |
6 | 6 | import platform |
7 | 7 | import shlex |
8 | | -import shutil |
9 | 8 | import subprocess |
10 | 9 | import sys |
11 | 10 | import typing |
@@ -300,73 +299,17 @@ def __exit__( |
300 | 299 | self.name = None |
301 | 300 |
|
302 | 301 | def copy_into(self, from_path: Path, to_path: PurePath) -> None: |
303 | | - # `docker cp` causes 'no space left on device' error when |
304 | | - # a container is running and the host filesystem is |
305 | | - # mounted. https://github.com/moby/moby/issues/38995 |
306 | | - # Use `docker exec` instead. |
307 | | - |
308 | 302 | if from_path.is_dir(): |
309 | 303 | self.call(["mkdir", "-p", to_path]) |
310 | | - subprocess.run( |
311 | | - f"tar cf - . | {self.engine.name} exec -i {self.name} tar --no-same-owner -xC {shell_quote(to_path)} -f -", |
312 | | - shell=True, |
313 | | - check=True, |
314 | | - cwd=from_path, |
315 | | - ) |
| 304 | + call(self.engine.name, "cp", f"{from_path}/.", f"{self.name}:{to_path}") |
316 | 305 | else: |
317 | | - exec_process: subprocess.Popen[bytes] |
318 | | - with subprocess.Popen( |
319 | | - [ |
320 | | - self.engine.name, |
321 | | - "exec", |
322 | | - "-i", |
323 | | - str(self.name), |
324 | | - "sh", |
325 | | - "-c", |
326 | | - f"cat > {shell_quote(to_path)}", |
327 | | - ], |
328 | | - stdin=subprocess.PIPE, |
329 | | - ) as exec_process: |
330 | | - assert exec_process.stdin |
331 | | - with open(from_path, "rb") as from_file: |
332 | | - # Bug in mypy, https://github.com/python/mypy/issues/15031 |
333 | | - shutil.copyfileobj(from_file, exec_process.stdin) # type: ignore[misc] |
334 | | - |
335 | | - exec_process.stdin.close() |
336 | | - exec_process.wait() |
337 | | - |
338 | | - if exec_process.returncode: |
339 | | - raise subprocess.CalledProcessError( |
340 | | - exec_process.returncode, exec_process.args, None, None |
341 | | - ) |
| 306 | + self.call(["mkdir", "-p", to_path.parent]) |
| 307 | + call(self.engine.name, "cp", from_path, f"{self.name}:{to_path}") |
342 | 308 |
|
343 | 309 | def copy_out(self, from_path: PurePath, to_path: Path) -> None: |
344 | 310 | # note: we assume from_path is a dir |
345 | 311 | to_path.mkdir(parents=True, exist_ok=True) |
346 | | - |
347 | | - if self.engine.name == "podman": |
348 | | - subprocess.run( |
349 | | - [ |
350 | | - self.engine.name, |
351 | | - "cp", |
352 | | - f"{self.name}:{from_path}/.", |
353 | | - str(to_path), |
354 | | - ], |
355 | | - check=True, |
356 | | - cwd=to_path, |
357 | | - ) |
358 | | - elif self.engine.name == "docker": |
359 | | - # There is a bug in docker that prevents a simple 'cp' invocation |
360 | | - # from working https://github.com/moby/moby/issues/38995 |
361 | | - command = f"{self.engine.name} exec -i {self.name} tar -cC {shell_quote(from_path)} -f - . | tar -xf -" |
362 | | - subprocess.run( |
363 | | - command, |
364 | | - shell=True, |
365 | | - check=True, |
366 | | - cwd=to_path, |
367 | | - ) |
368 | | - else: |
369 | | - raise KeyError(self.engine.name) |
| 312 | + call(self.engine.name, "cp", f"{self.name}:{from_path}/.", to_path) |
370 | 313 |
|
371 | 314 | def glob(self, path: PurePosixPath, pattern: str) -> list[PurePosixPath]: |
372 | 315 | glob_pattern = path.joinpath(pattern) |
|
0 commit comments