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.
This commit is contained in:
clayton craft 2017-08-18 09:25:58 -07:00 committed by Oliver Smith
parent 341c809874
commit d0f09ca0d0
3 changed files with 17 additions and 6 deletions

View File

@ -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])

View File

@ -17,12 +17,14 @@ You should have received a copy of the GNU General Public License
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
"""
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!")

View File

@ -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)