From ba3e2f6d265a6b14308aca14b82cb0bc819f3350 Mon Sep 17 00:00:00 2001 From: drebrez Date: Thu, 2 Nov 2017 18:33:14 +0100 Subject: [PATCH] Add argument to zap (-o) older versions of packages from all chroots (#841) - also moved the mismatch clean (-m) before zapping the chroots - added confirmation questions to -o and -m --- pmb/chroot/zap.py | 38 +++++++++++++++++++++++++++++++------- pmb/helpers/frontend.py | 3 ++- pmb/parse/arguments.py | 2 ++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/pmb/chroot/zap.py b/pmb/chroot/zap.py index daa3d37c..e33f9ccf 100644 --- a/pmb/chroot/zap.py +++ b/pmb/chroot/zap.py @@ -24,7 +24,8 @@ import pmb.chroot import pmb.helpers.run -def zap(args, confirm=True, packages=False, http=False, mismatch_bins=False, distfiles=False): +def zap(args, confirm=True, packages=False, http=False, mismatch_bins=False, + old_bins=False, distfiles=False): """ Shutdown everything inside the chroots (e.g. distccd, adb), umount everything and then safely remove folders from the work-directory. @@ -33,11 +34,22 @@ def zap(args, confirm=True, packages=False, http=False, mismatch_bins=False, dis :arg http: Clear the http cache (used e.g. for the initial apk download) :arg mismatch_bins: Remove the packages, that have a different version compared to what is in the abuilds folder. + :arg old_bins: Clean out outdated binary packages downloaded from + mirrors (e.g. from Alpine) :arg distfiles: Clear the downloaded files cache NOTE: This function gets called in pmb/config/init.py, with only args.work and args.device set! """ + + # Delete packages with a different version compared to aports, then re-index + if mismatch_bins: + zap_mismatch_bins(args, confirm) + + # Delete outdated binary packages + if old_bins: + zap_old_bins(args, confirm) + pmb.chroot.shutdown(args) # Deletion patterns for folders inside args.work @@ -61,13 +73,13 @@ def zap(args, confirm=True, packages=False, http=False, mismatch_bins=False, dis if not confirm or pmb.helpers.cli.confirm(args, "Remove " + match + "?"): pmb.helpers.run.root(args, ["rm", "-rf", match]) - # Delete packages with a different version compared to aports, then re-index - if mismatch_bins and os.path.exists(args.work + "/packages/"): - binaries(args) - pmb.build.other.index_repo(args) - -def binaries(args): +def zap_mismatch_bins(args, confirm=True): + if not os.path.exists(args.work + "/packages/"): + return + if confirm and not pmb.helpers.cli.confirm(args, "Remove packages that are newer than" + " the corresponding package in aports?"): + return for arch in os.listdir(os.path.realpath(args.work + "/packages/")): arch_pkg_path = os.path.realpath(args.work) + "/packages/" + arch # Delete all broken symbolic links @@ -93,3 +105,15 @@ def binaries(args): aport_version + "): " + arch + "/" + bin_pkgname + "-" + bin_version + ".apk") pmb.helpers.run.root(args, ["rm", bin_apk_path]) + pmb.build.other.index_repo(args) + + +def zap_old_bins(args, confirm=True): + if confirm and not pmb.helpers.cli.confirm(args, "Remove outdated binary packages?"): + return + arch_native = pmb.parse.arch.alpine_native() + if os.path.exists(args.work + "/cache_apk_" + arch_native): + pmb.chroot.root(args, ["apk", "-v", "cache", "clean"]) + for arch in pmb.config.build_device_architectures: + if arch != arch_native and os.path.exists(args.work + "/cache_apk_" + arch): + pmb.chroot.root(args, ["apk", "-v", "cache", "clean"], "buildroot_" + arch) diff --git a/pmb/helpers/frontend.py b/pmb/helpers/frontend.py index b090f25c..6f447815 100644 --- a/pmb/helpers/frontend.py +++ b/pmb/helpers/frontend.py @@ -221,4 +221,5 @@ def log_distccd(args): def zap(args): pmb.chroot.zap(args, packages=args.packages, http=args.http, - mismatch_bins=args.mismatch_bins, distfiles=args.distfiles) + mismatch_bins=args.mismatch_bins, old_bins=args.old_bins, + distfiles=args.distfiles) diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index dffeba50..66b04c48 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -174,6 +174,8 @@ def arguments(): zap.add_argument("-m", "--mismatch-bins", action="store_true", help="also delete" " binary packages that are newer than the corresponding" " package in aports") + zap.add_argument("-o", "--old-bins", action="store_true", help="also delete outdated" + " binary packages downloaded from mirrors (e.g. from Alpine)") zap.add_argument("-d", "--distfiles", action="store_true", help="also delete" " downloaded files cache")