]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Use chunked reads when inserting partition
authorMichael A Cassaniti <michael@cassaniti.id.au>
Wed, 17 Aug 2022 05:52:53 +0000 (15:52 +1000)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 18 Aug 2022 09:29:33 +0000 (11:29 +0200)
mkosi/__init__.py

index 9d0c8c424571f0cbfb013d35cf765096bfb989f6..f540f768f5e41393995bdee08eff427e9aa4dbd0 100644 (file)
@@ -3713,7 +3713,10 @@ def insert_partition(
             # Let's discard the partition block device first, to ensure the GPT partition table footer that
             # likely is stored in it is flushed out. After all we want to write with dd's sparse option.
             run(["blkdiscard", path])
-            path.write_bytes(blob.read())
+
+            # Without this the entire blob will be read into memory which could exceed system memory
+            with open(path, mode='wb') as path_fp:
+                os.sendfile(path_fp.fileno(), blob.fileno(), offset=0, count=blob_size)
 
     return part