From 94039c19bb8aaf64cd188539c9746b69a8452570 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 3 Nov 2021 16:09:11 +0100 Subject: [PATCH] [unpackfs] Use callback instead of building giant string in memory SEE #1740 By processing each line in turn (and just counting is) rather than collecting all of the lines of output from the tools, we end up with lower memory usage. --- src/modules/unpackfs/main.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/modules/unpackfs/main.py b/src/modules/unpackfs/main.py index 020db370c..4ab718213 100644 --- a/src/modules/unpackfs/main.py +++ b/src/modules/unpackfs/main.py @@ -79,24 +79,24 @@ class UnpackEntry: """ Counts the number of files this entry has. """ - fslist = "" + # Need a name we can use like a global + class counter(object): + count = 0 + def cb_count(s): + counter.count += 1 if self.sourcefs == "squashfs": - fslist = subprocess.check_output( - ["unsquashfs", "-l", self.source] - ) + libcalamares.utils.host_env_process_output(["unsquashfs", "-l", self.source], cb_count) elif self.sourcefs == "ext4": - fslist = subprocess.check_output( - ["find", self.mountPoint, "-type", "f"] - ) + libcalamares.utils.host_env_process_output(["find", self.mountPoint, "-type", "f"], cb_count) elif self.is_file(): # Hasn't been mounted, copy directly; find handles both # files and directories. - fslist = subprocess.check_output(["find", self.source, "-type", "f"]) + libcalamares.utils.host_env_process_output(["find", self.source, "-type", "f"], cb_count) - self.total = len(fslist.splitlines()) + self.total = counter.count return self.total def do_mount(self, base):