From 795bd1fd9eaa5a306fc3c783e1e5e0cbd6b106f4 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 9 Sep 2025 20:11:11 -0700 Subject: [PATCH] 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 Reviewed-by: James Valleroy --- plinth/modules/torproxy/privileged.py | 7 +------ plinth/modules/torproxy/utils.py | 9 +++++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/plinth/modules/torproxy/privileged.py b/plinth/modules/torproxy/privileged.py index 93ea17d2d..8ce68cc2a 100644 --- a/plinth/modules/torproxy/privileged.py +++ b/plinth/modules/torproxy/privileged.py @@ -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): diff --git a/plinth/modules/torproxy/utils.py b/plinth/modules/torproxy/utils.py index 82f1e810e..9a582625a 100644 --- a/plinth/modules/torproxy/utils.py +++ b/plinth/modules/torproxy/utils.py @@ -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