forked from Mirror/pmbootstrap
pmb.chroot.init: warn about outdated chroots (MR 2293)
Prepare to remove the outdated chroot check from "pmbootstrap status". Display it when the user enters a stale chroot instead. This way the user is more likely to see it, and we can make "pmbootstrap status" more minimal (by removing all checks, in future patches). Related: issue 1903
This commit is contained in:
parent
2972f1d36e
commit
ed8e7c1f85
2 changed files with 31 additions and 7 deletions
|
@ -14,6 +14,7 @@ import pmb.helpers.repo
|
||||||
import pmb.helpers.run
|
import pmb.helpers.run
|
||||||
import pmb.parse.arch
|
import pmb.parse.arch
|
||||||
|
|
||||||
|
cache_chroot_is_outdated = []
|
||||||
|
|
||||||
class UsrMerge(enum.Enum):
|
class UsrMerge(enum.Enum):
|
||||||
"""
|
"""
|
||||||
|
@ -92,6 +93,22 @@ def init_usr_merge(args, suffix):
|
||||||
f"{args.work}/chroot_{suffix}"])
|
f"{args.work}/chroot_{suffix}"])
|
||||||
|
|
||||||
|
|
||||||
|
def warn_if_chroot_is_outdated(args, suffix):
|
||||||
|
global cache_chroot_is_outdated
|
||||||
|
|
||||||
|
# Only check / display the warning once per session
|
||||||
|
if suffix in cache_chroot_is_outdated:
|
||||||
|
return
|
||||||
|
|
||||||
|
if pmb.config.workdir.chroots_outdated(args, suffix):
|
||||||
|
days_warn = int(pmb.config.chroot_outdated / 3600 / 24)
|
||||||
|
logging.warning(f"WARNING: Your {suffix} chroot is older than"
|
||||||
|
f" {days_warn} days. Consider running"
|
||||||
|
" 'pmbootstrap zap'.")
|
||||||
|
|
||||||
|
cache_chroot_is_outdated += [suffix]
|
||||||
|
|
||||||
|
|
||||||
def init(args, suffix="native", usr_merge=UsrMerge.AUTO,
|
def init(args, suffix="native", usr_merge=UsrMerge.AUTO,
|
||||||
postmarketos_mirror=True):
|
postmarketos_mirror=True):
|
||||||
"""
|
"""
|
||||||
|
@ -115,6 +132,7 @@ def init(args, suffix="native", usr_merge=UsrMerge.AUTO,
|
||||||
pmb.config.workdir.chroot_check_channel(args, suffix)
|
pmb.config.workdir.chroot_check_channel(args, suffix)
|
||||||
copy_resolv_conf(args, suffix)
|
copy_resolv_conf(args, suffix)
|
||||||
pmb.chroot.apk.update_repository_list(args, suffix, postmarketos_mirror)
|
pmb.chroot.apk.update_repository_list(args, suffix, postmarketos_mirror)
|
||||||
|
warn_if_chroot_is_outdated(args, suffix)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Require apk-tools-static
|
# Require apk-tools-static
|
||||||
|
|
|
@ -35,11 +35,15 @@ def chroot_save_init(args, suffix):
|
||||||
cfg.write(handle)
|
cfg.write(handle)
|
||||||
|
|
||||||
|
|
||||||
def chroots_outdated(args):
|
def chroots_outdated(args, suffix=None):
|
||||||
""" Check if init dates from workdir.cfg indicate that any chroot is
|
"""Check if init dates from workdir.cfg indicate that any chroot is
|
||||||
outdated.
|
outdated.
|
||||||
:returns: True if any of the chroots are outdated and should be zapped,
|
|
||||||
False otherwise """
|
:param suffix: only check a specific chroot suffix
|
||||||
|
|
||||||
|
:returns: True if any of the chroots are outdated and should be zapped,
|
||||||
|
False otherwise
|
||||||
|
"""
|
||||||
# Skip if workdir.cfg doesn't exist
|
# Skip if workdir.cfg doesn't exist
|
||||||
path = args.work + "/workdir.cfg"
|
path = args.work + "/workdir.cfg"
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
|
@ -52,8 +56,10 @@ def chroots_outdated(args):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
date_outdated = time.time() - pmb.config.chroot_outdated
|
date_outdated = time.time() - pmb.config.chroot_outdated
|
||||||
for suffix in cfg[key]:
|
for cfg_suffix in cfg[key]:
|
||||||
date_init = int(cfg[key][suffix])
|
if suffix and cfg_suffix != suffix:
|
||||||
|
continue
|
||||||
|
date_init = int(cfg[key][cfg_suffix])
|
||||||
if date_init <= date_outdated:
|
if date_init <= date_outdated:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue