Skip to content

Commit 415a7c3

Browse files
committed
fix: use docker cp instead of tar
1 parent cc52272 commit 415a7c3

File tree

1 file changed

+4
-61
lines changed

1 file changed

+4
-61
lines changed

cibuildwheel/oci_container.py

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os
66
import platform
77
import shlex
8-
import shutil
98
import subprocess
109
import sys
1110
import typing
@@ -300,73 +299,17 @@ def __exit__(
300299
self.name = None
301300

302301
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-
308302
if from_path.is_dir():
309303
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}")
316305
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}")
342308

343309
def copy_out(self, from_path: PurePath, to_path: Path) -> None:
344310
# note: we assume from_path is a dir
345311
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)
370313

371314
def glob(self, path: PurePosixPath, pattern: str) -> list[PurePosixPath]:
372315
glob_pattern = path.joinpath(pattern)

0 commit comments

Comments
 (0)