]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Use input instead of writing to stdin in make_cpio()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 22 Jul 2023 18:20:48 +0000 (20:20 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 24 Jul 2023 19:41:57 +0000 (21:41 +0200)
Also remove the text= argument from spawn() and default it to True
just like run().

mkosi/__init__.py
mkosi/run.py

index 625b011c32d9c4817269049c4dc75e114b485328..506876ecd5f696c766300d45b8e48d5e861408b6 100644 (file)
@@ -40,7 +40,7 @@ from mkosi.mounts import mount_overlay, mount_passwd, mount_tools, scandir_recur
 from mkosi.pager import page
 from mkosi.qemu import copy_ephemeral, machine_cid, run_qemu
 from mkosi.remove import unlink_try_hard
-from mkosi.run import become_root, bwrap, chroot_cmd, init_mount_namespace, run, spawn
+from mkosi.run import become_root, bwrap, chroot_cmd, init_mount_namespace, run
 from mkosi.state import MkosiState
 from mkosi.tree import copy_tree, move_tree
 from mkosi.types import PathString
@@ -623,7 +623,7 @@ def make_initrd(state: MkosiState) -> None:
 
 def make_cpio(state: MkosiState, files: Iterator[Path], output: Path) -> None:
     with complete_step(f"Creating cpio {output}…"):
-        cmd: list[PathString] = [
+        run([
             "cpio",
             "-o",
             "--reproducible",
@@ -631,17 +631,8 @@ def make_cpio(state: MkosiState, files: Iterator[Path], output: Path) -> None:
             "-H", "newc",
             "--quiet",
             "-D", state.root,
-            "-O", output
-        ]
-
-        with spawn(cmd, stdin=subprocess.PIPE, text=True) as cpio:
-            #  https://github.com/python/mypy/issues/10583
-            assert cpio.stdin is not None
-
-            for file in files:
-                cpio.stdin.write(os.fspath(file))
-                cpio.stdin.write("\0")
-            cpio.stdin.close()
+            "-O", output,
+        ], input="\0".join(os.fspath(file) for file in files))
 
 
 def make_directory(state: MkosiState) -> None:
index 6a04eed7816a3f529d57976d47be07033b52c645..111266f9bac157ca4103c1191d047454ec72210b 100644 (file)
@@ -219,7 +219,6 @@ def spawn(
     stdin: _FILE = None,
     stdout: _FILE = None,
     stderr: _FILE = None,
-    text: bool = True,
     user: Optional[int] = None,
     group: Optional[int] = None,
 ) -> Popen:
@@ -238,7 +237,7 @@ def spawn(
             stdin=stdin,
             stdout=stdout,
             stderr=stderr,
-            text=text,
+            text=True,
             user=user,
             group=group,
             preexec_fn=foreground,