mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
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:
parent
0e78cfb8c7
commit
795bd1fd9e
@ -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):
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user