From a55f75d5e87044c4d4e7ea4640957bb6bd033909 Mon Sep 17 00:00:00 2001 From: derrod Date: Sun, 6 Sep 2020 05:57:28 +0200 Subject: [PATCH] [core/downloader] Prevent file deletion when using delta manifest This is technically not how we should do this. In theory we should "overlay" the delta manifest over the proper one and simply add/replace the chunk/file list entries with the one from the delta manifest. However simply not deleting files also works for the time being since files are rarely deleted anyways. --- legendary/core.py | 5 ++++- legendary/downloader/manager.py | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/legendary/core.py b/legendary/core.py index a75d3e0..3662dd5 100644 --- a/legendary/core.py +++ b/legendary/core.py @@ -662,6 +662,7 @@ class LegendaryCore: ) -> (DLManager, AnalysisResult, ManifestMeta): # load old manifest old_manifest = None + delta_manifest_used = False # load old manifest if we have one if override_old_manifest: @@ -711,6 +712,7 @@ class LegendaryCore: f'"{old_manifest.meta.build_id}" to' f'"{new_manifest.meta.build_id}"...') new_manifest = delta_manifest + delta_manifest_used = True else: self.log.debug(f'No Delta manifest received from CDN.') @@ -782,7 +784,8 @@ class LegendaryCore: file_prefix_filter=file_prefix_filter, file_exclude_filter=file_exclude_filter, file_install_tag=file_install_tag, - processing_optimization=process_opt) + processing_optimization=process_opt, + delta_manifest_used=delta_manifest_used) prereq = None if new_manifest.meta.prereq_ids: diff --git a/legendary/downloader/manager.py b/legendary/downloader/manager.py index 772aa02..60293a0 100644 --- a/legendary/downloader/manager.py +++ b/legendary/downloader/manager.py @@ -79,7 +79,7 @@ class DLManager(Process): def run_analysis(self, manifest: Manifest, old_manifest: Manifest = None, patch=True, resume=True, file_prefix_filter=None, file_exclude_filter=None, file_install_tag=None, - processing_optimization=False) -> AnalysisResult: + processing_optimization=False, delta_manifest_used=False) -> AnalysisResult: """ Run analysis on manifest and old manifest (if not None) and return a result with a summary resources required in order to install the provided manifest. @@ -92,6 +92,7 @@ class DLManager(Process): :param file_exclude_filter: Exclude files with this prefix from download :param file_install_tag: Only install files with the specified tag :param processing_optimization: Attempt to optimize processing order and RAM usage + :param delta_manifest_used: whether or not the manifest is a delta manifest :return: AnalysisResult """ @@ -181,6 +182,10 @@ class DLManager(Process): analysis_res.install_size = sum(fm.file_size for fm in manifest.file_manifest_list.elements if fm.filename in mc.added) + # todo properly handle delta manifests + if delta_manifest_used: + mc.removed = set() + if mc.removed: analysis_res.removed = len(mc.removed) self.log.debug(f'{analysis_res.removed} removed files')