From 202f07973a4f41fb5f6d317db727633a8413c560 Mon Sep 17 00:00:00 2001 From: derrod Date: Sun, 2 Jan 2022 13:06:59 +0100 Subject: [PATCH] [downloader/models] Calculate maximum disk space delta during installation --- legendary/downloader/mp/manager.py | 16 ++++++++++++++++ legendary/models/downloading.py | 1 + 2 files changed, 17 insertions(+) diff --git a/legendary/downloader/mp/manager.py b/legendary/downloader/mp/manager.py index ad3c07c..1a1ab2f 100644 --- a/legendary/downloader/mp/manager.py +++ b/legendary/downloader/mp/manager.py @@ -208,6 +208,8 @@ class DLManager(Process): fmlist = sorted(manifest.file_manifest_list.elements, key=lambda a: a.filename.lower()) + # Create reference count for chunks and calculate additional/temporary disk size required for install + current_tmp_size = 0 for fm in fmlist: self.hash_map[fm.filename] = fm.sha_hash.hex() @@ -219,6 +221,20 @@ class DLManager(Process): for cp in fm.chunk_parts: references[cp.guid_num] += 1 + if fm.filename in mc.added: + # if the file was added, it just adds to the delta + current_tmp_size += fm.file_size + analysis_res.disk_space_delta = max(current_tmp_size, analysis_res.disk_space_delta) + elif fm.filename in mc.changed: + # if the file was changed, we need temporary space equal to the full size, + # but then subtract the size of the old file as it's deleted on write completion. + current_tmp_size += fm.file_size + analysis_res.disk_space_delta = max(current_tmp_size, analysis_res.disk_space_delta) + current_tmp_size -= old_manifest.file_manifest_list.get_file_by_path(fm.filename).file_size + + # clamp to 0 + self.log.debug(f'Disk space delta: {analysis_res.disk_space_delta/1024/1024:.02f} MiB') + if processing_optimization: s_time = time.time() # reorder the file manifest list to group files that share many chunks diff --git a/legendary/models/downloading.py b/legendary/models/downloading.py index a0538e4..d2d945a 100644 --- a/legendary/models/downloading.py +++ b/legendary/models/downloading.py @@ -127,6 +127,7 @@ class AnalysisResult: dl_size: int = 0 uncompressed_dl_size: int = 0 install_size: int = 0 + disk_space_delta: int = 0 reuse_size: int = 0 biggest_file_size: int = 0 unchanged_size: int = 0