From 29d3e98b81d77a68f36d64e1f6ccbf8384412966 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Sat, 25 Mar 2023 10:36:23 -0600 Subject: [PATCH] kdk_handler.py: Fix pkg detection --- resources/kdk_handler.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/resources/kdk_handler.py b/resources/kdk_handler.py index a024b09927..60219fe29f 100644 --- a/resources/kdk_handler.py +++ b/resources/kdk_handler.py @@ -448,14 +448,13 @@ def _remove_kdk(self, kdk_path: str) -> None: logging.warning(f"- KDK does not exist: {kdk_path}") return - rm_args = ["rm", "-f", kdk_path] - if Path(kdk_path).is_dir(): - rm_args = ["rm", "-rf", kdk_path] + rm_args = ["rm", "-rf" if Path(kdk_path).is_dir() else "-f", kdk_path] result = utilities.elevated(rm_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if result.returncode != 0: logging.warning(f"- Failed to remove KDK: {kdk_path}") logging.warning(f"- {result.stdout.decode('utf-8')}") + return logging.info(f"- Successfully removed KDK: {kdk_path}") @@ -486,18 +485,17 @@ def _remove_unused_kdks(self, exclude_builds: list = None) -> None: logging.info("- Cleaning unused KDKs") for kdk_folder in Path(KDK_INSTALL_PATH).iterdir(): - if kdk_folder.is_dir(): - if kdk_folder.name.endswith(".kdk") or kdk_folder.name.endswith(".pkg"): - should_remove = True - for build in exclude_builds: - if build != "": - continue - if kdk_folder.name.endswith(f"{build}.kdk") or kdk_folder.name.endswith(f"{build}.pkg"): - should_remove = False - break - if should_remove is False: + if kdk_folder.name.endswith(".kdk") or kdk_folder.name.endswith(".pkg"): + should_remove = True + for build in exclude_builds: + if build != "": continue - self._remove_kdk(kdk_folder) + if kdk_folder.name.endswith(f"_{build}.kdk") or kdk_folder.name.endswith(f"_{build}.pkg"): + should_remove = False + break + if should_remove is False: + continue + self._remove_kdk(kdk_folder) def validate_kdk_checksum(self, kdk_dmg_path: str = None) -> bool: