From 5412bd75d775273a592020424dbfa3421d1b5339 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Tue, 22 Jun 2021 22:29:11 -0400 Subject: [PATCH] action_utils: Separate function to hold freedombox package Signed-off-by: James Valleroy --- actions/packages | 4 ++-- actions/upgrades | 8 ++++---- plinth/action_utils.py | 18 ++++++++++++++---- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/actions/packages b/actions/packages index ad6390a11..ff15e9df6 100755 --- a/actions/packages +++ b/actions/packages @@ -18,7 +18,7 @@ import apt.cache import apt_inst import apt_pkg from plinth import cfg -from plinth.action_utils import apt_hold, run_apt_command +from plinth.action_utils import apt_hold_freedombox, run_apt_command LOCK_FILE = '/var/lib/dpkg/lock' @@ -93,7 +93,7 @@ def subcommand_install(arguments): extra_arguments += ['-o', 'Dpkg::Options::=--force-confmiss'] subprocess.run(['dpkg', '--configure', '-a']) - with apt_hold(): + with apt_hold_freedombox(): run_apt_command(['--fix-broken', 'install']) returncode = run_apt_command(['install'] + extra_arguments + arguments.packages) diff --git a/actions/upgrades b/actions/upgrades index 401fb6299..242a87093 100755 --- a/actions/upgrades +++ b/actions/upgrades @@ -14,9 +14,9 @@ import subprocess import sys import time -from plinth.action_utils import (apt_hold, debconf_set_selections, - run_apt_command, service_daemon_reload, - service_restart) +from plinth.action_utils import (apt_hold, apt_hold_freedombox, + debconf_set_selections, run_apt_command, + service_daemon_reload, service_restart) from plinth.modules.apache.components import check_url from plinth.modules.snapshot import (is_apt_snapshots_enabled, is_supported as snapshot_is_supported, load_augeas as @@ -432,7 +432,7 @@ def _perform_dist_upgrade(): # Hold freedombox package during entire dist upgrade. print('Holding freedombox package...', flush=True) - with apt_hold(): + with apt_hold_freedombox(): print('Updating Apt cache...', flush=True) run_apt_command(['update']) diff --git a/plinth/action_utils.py b/plinth/action_utils.py index 09a7f3f09..7f737e17a 100644 --- a/plinth/action_utils.py +++ b/plinth/action_utils.py @@ -418,11 +418,8 @@ def run_apt_command(arguments): @contextmanager -def apt_hold(packages=None, ignore_errors=False): +def apt_hold(packages, ignore_errors=False): """Prevent packages from being removed during apt operations.""" - if not packages: - packages = ['freedombox'] - current_hold = subprocess.check_output(['apt-mark', 'showhold'] + packages) try: yield current_hold or subprocess.run(['apt-mark', 'hold'] + packages, @@ -431,3 +428,16 @@ def apt_hold(packages=None, ignore_errors=False): if not current_hold: subprocess.run(['apt-mark', 'unhold'] + packages, check=not ignore_errors) + + +@contextmanager +def apt_hold_freedombox(): + """Prevent freedombox package from being removed during apt operations.""" + current_hold = subprocess.check_output( + ['apt-mark', 'showhold', 'freedombox']) + try: + yield current_hold or subprocess.check_call( + ['apt-mark', 'hold', 'freedombox']) + finally: + if not current_hold: + subprocess.check_call(['apt-mark', 'unhold', 'freedombox'])