Skip to content

Commit 2b4a853

Browse files
authored
fix: ensure that deep paths exist before copying files. (pypa#2418)
1 parent 2d6b40d commit 2b4a853

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

cibuildwheel/oci_container.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ def copy_into(self, from_path: Path, to_path: PurePath) -> None:
342342
)
343343
else:
344344
exec_process: subprocess.Popen[bytes]
345+
self.call(["mkdir", "-p", to_path.parent])
345346
with subprocess.Popen(
346347
[
347348
self.engine.name,

unit_test/oci_container_test.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,23 @@ def test_binary_output(container_engine):
239239
assert output == binary_data_string
240240

241241

242-
def test_file_operation(tmp_path: Path, container_engine: OCIContainerEngineConfig) -> None:
242+
@pytest.mark.parametrize(
243+
"file_path",
244+
["test.dat", "path/to/test.dat"],
245+
)
246+
def test_file_operation(
247+
tmp_path: Path, container_engine: OCIContainerEngineConfig, file_path: str
248+
) -> None:
243249
with OCIContainer(
244250
engine=container_engine, image=DEFAULT_IMAGE, oci_platform=DEFAULT_OCI_PLATFORM
245251
) as container:
246252
# test copying a file in
247253
test_binary_data = bytes(random.randrange(256) for _ in range(1000))
248-
original_test_file = tmp_path / "test.dat"
254+
original_test_file = tmp_path / file_path
255+
original_test_file.parent.mkdir(parents=True, exist_ok=True)
249256
original_test_file.write_bytes(test_binary_data)
250257

251-
dst_file = PurePath("/tmp/test.dat")
258+
dst_file = PurePath("/tmp") / file_path
252259

253260
container.copy_into(original_test_file, dst_file)
254261

0 commit comments

Comments
 (0)