From d0f09ca0d0a9b9f208d8b478ad357a55845f7fff Mon Sep 17 00:00:00 2001 From: clayton craft Date: Fri, 18 Aug 2017 09:25:58 -0700 Subject: [PATCH] Resolve #361 by zapping existing chroots after init (#385) This extends zap() to add a 'no_confirm' option (False by default), and zap() is now called by init with no_confirm=True to automatically zap any existing chroots after the user runs init. This helps insure that what is installed in the chroots is exactly what the user expects after setting options in init. Additionally, we create `cache_http` to verify write access to the work folder instead of `chroot_native`. So we can ask for zapping only if no chroot folder exists. --- pmb/chroot/zap.py | 8 ++++---- pmb/config/init.py | 13 ++++++++++++- pmb/helpers/frontend.py | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pmb/chroot/zap.py b/pmb/chroot/zap.py index bb9f2b0a..f03a5155 100644 --- a/pmb/chroot/zap.py +++ b/pmb/chroot/zap.py @@ -23,7 +23,7 @@ import pmb.chroot import pmb.helpers.run -def zap(args): +def zap(args, confirm=True, packages=False, http=False): pmb.chroot.shutdown(args) patterns = [ "chroot_native", @@ -33,14 +33,14 @@ def zap(args): # Only ask for removal, if the user specificed the extra '-p' switch. # Deleting the packages by accident is really annoying. - if args.packages: + if packages: patterns += ["packages"] - if args.http: + if http: patterns += ["cache_http"] for pattern in patterns: pattern = os.path.realpath(args.work + "/" + pattern) matches = glob.glob(pattern) for match in matches: - if pmb.helpers.cli.confirm(args, "Remove " + match + "?"): + if not confirm or pmb.helpers.cli.confirm(args, "Remove " + match + "?"): pmb.helpers.run.root(args, ["rm", "-rf", match]) diff --git a/pmb/config/init.py b/pmb/config/init.py index 7140eb54..b4770780 100644 --- a/pmb/config/init.py +++ b/pmb/config/init.py @@ -17,12 +17,14 @@ You should have received a copy of the GNU General Public License along with pmbootstrap. If not, see . """ import logging +import glob import os import pmb.config import pmb.helpers.cli import pmb.helpers.devices import pmb.helpers.ui +import pmb.chroot.zap def ask_for_work_path(args): @@ -39,7 +41,7 @@ def ask_for_work_path(args): ret = os.path.expanduser(pmb.helpers.cli.ask( args, "Work path", None, args.work, False)) os.makedirs(ret, 0o700, True) - os.makedirs(ret + "/chroot_native", 0o755, True) + os.makedirs(ret + "/cache_http", 0o700, True) return ret except OSError: logging.fatal("ERROR: Could not create this folder, or write" @@ -102,9 +104,18 @@ def init(args): # Save config pmb.config.save(args, cfg) + if len(glob.glob(args.work + "/chroot_*")) and pmb.helpers.cli.confirm(args, "Zap existing chroots to apply configuration?", default=True): + if not os.path.exists(args.aports + "/device/device-" + args.device + "/deviceinfo"): + setattr(args, "deviceinfo", None) + else: + setattr(args, "deviceinfo", pmb.parse.deviceinfo(args)) + # Do not zap any existing packages or cache_http directories + pmb.chroot.zap(args, confirm=False) + logging.info( "WARNING: The applications in the chroots do not get updated automatically.") logging.info("Run 'pmbootstrap zap' to delete all chroots once a day before" " working with pmbootstrap!") logging.info("It only takes a few seconds, and all packages are cached.") + logging.info("Done!") diff --git a/pmb/helpers/frontend.py b/pmb/helpers/frontend.py index b0a4be51..ed10bd35 100644 --- a/pmb/helpers/frontend.py +++ b/pmb/helpers/frontend.py @@ -164,4 +164,4 @@ def log_distccd(args): def zap(args): - pmb.chroot.zap(args) + pmb.chroot.zap(args, packages=args.packages, http=args.http)