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 = []
for package in packages:
current_hold = subprocess.check_output(
['apt-mark', 'showhold', package])
if not current_hold:
process = subprocess.run(['apt-mark', 'hold', package],
check=False)
if process.returncode == 0: # success
held_packages.append(package)
try:
for package in packages:
current_hold = subprocess.check_output(
['apt-mark', 'showhold', package])
if not current_hold:
process = subprocess.run(['apt-mark', 'hold', package],
check=False)
if process.returncode == 0: # success
held_packages.append(package)
yield held_packages
for package in held_packages:
subprocess.check_call(['apt-mark', 'unhold', package])
yield held_packages
finally:
for package in held_packages:
subprocess.check_call(['apt-mark', 'unhold', package])
@contextmanager