torproxy: When disabling apt over tor fails, report error properly

- It is not possible to disable apt over tor for as many files as possible with
the current code because even an error in a single file will result in entire
process failing. Instead, implement a way to disable the exception.

Tests:

- Add an unparsable line into the one of the apt sources files. Disabling apt
over tor works and all file but the error file are modified.

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-09-09 20:11:11 -07:00 committed by James Valleroy
parent 0e78cfb8c7
commit 795bd1fd9e
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 6 additions and 10 deletions

View File

@ -161,12 +161,7 @@ def _enable_apt_transport_tor():
def _disable_apt_transport_tor():
"""Disable package download over Tor."""
try:
aug = get_augeas()
except Exception:
# Disable what we can, so APT is not unusable.
pass
aug = get_augeas(raise_exception=False)
for uri_path in iter_apt_uris(aug):
uri = aug.get(uri_path)
if uri.startswith(APT_TOR_PREFIX):

View File

@ -36,7 +36,7 @@ def iter_apt_uris(aug):
[aug.match(path) for path in APT_SOURCES_URI_PATHS])
def get_augeas():
def get_augeas(raise_exception=True):
"""Return an instance of Augeaus for processing APT configuration."""
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
augeas.Augeas.NO_MODL_AUTOLOAD)
@ -51,9 +51,10 @@ def get_augeas():
aug.load()
# Check for any errors in parsing sources lists.
if aug.match('/augeas/files/etc/apt/sources.list/error') or \
aug.match('/augeas/files/etc/apt/sources.list.d//error'):
raise Exception('Error parsing sources list')
if raise_exception:
if aug.match('/augeas/files/etc/apt/sources.list/error') or \
aug.match('/augeas/files/etc/apt/sources.list.d//error'):
raise Exception('Error parsing sources list')
return aug