action_utils: Ensure that package are unheld if dist upgrade fails

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2025-03-06 12:58:56 -08:00 committed by James Valleroy
parent 3aff47039f
commit 0022dc5889
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -475,19 +475,20 @@ def apt_hold(packages):
""" """
held_packages = [] held_packages = []
for package in packages: try:
current_hold = subprocess.check_output( for package in packages:
['apt-mark', 'showhold', package]) current_hold = subprocess.check_output(
if not current_hold: ['apt-mark', 'showhold', package])
process = subprocess.run(['apt-mark', 'hold', package], if not current_hold:
check=False) process = subprocess.run(['apt-mark', 'hold', package],
if process.returncode == 0: # success check=False)
held_packages.append(package) if process.returncode == 0: # success
held_packages.append(package)
yield held_packages yield held_packages
finally:
for package in held_packages: for package in held_packages:
subprocess.check_call(['apt-mark', 'unhold', package]) subprocess.check_call(['apt-mark', 'unhold', package])
@contextmanager @contextmanager