From 25d32d245af8952c4d208623f3121d0eff8e5e43 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Sat, 19 Nov 2022 19:56:26 -0500 Subject: [PATCH] tor: Also use Aptsources822 augeas lens This will handle sources files with Deb822 format. Closes: #214. Tests: - Enable package download through Tor. "tor+" is prepended to sources URL. - Disable package download through Tor. "tor+" is removed from sources URL. Signed-off-by: James Valleroy Reviewed-by: Sunil Mohan Adapa --- plinth/modules/tor/utils.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/plinth/modules/tor/utils.py b/plinth/modules/tor/utils.py index f91ecba5e..ff53b9c9a 100644 --- a/plinth/modules/tor/utils.py +++ b/plinth/modules/tor/utils.py @@ -1,7 +1,6 @@ # SPDX-License-Identifier: AGPL-3.0-or-later """Tor utility functions.""" -import glob import itertools import augeas @@ -13,7 +12,8 @@ from plinth.modules.names.components import DomainName from . import privileged APT_SOURCES_URI_PATHS = ('/files/etc/apt/sources.list/*/uri', - '/files/etc/apt/sources.list.d/*/*/uri') + '/files/etc/apt/sources.list.d/*/*/uri', + '/files/etc/apt/sources.list.d/*/*/URIs/*') APT_TOR_PREFIX = 'tor+' @@ -72,20 +72,16 @@ def get_augeas(): '/etc/apt/sources.list') aug.set('/augeas/load/Aptsources/incl[last() + 1]', '/etc/apt/sources.list.d/*.list') + aug.set('/augeas/load/Aptsources822/lens', 'Aptsources822.lns') + aug.set('/augeas/load/Aptsources822/incl[last() + 1]', + '/etc/apt/sources.list.d/*.sources') aug.load() - # Currently, augeas does not handle Deb822 format, it error out. + # 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') - # Starting with Apt 1.1, /etc/apt/sources.list.d/*.sources will - # contain files with Deb822 format. If they are found, error out - # for now. XXX: Provide proper support Deb822 format with a new - # Augeas lens. - if glob.glob('/etc/apt/sources.list.d/*.sources'): - raise Exception('Can not handle Deb822 source files') - return aug @@ -94,8 +90,7 @@ def is_apt_transport_tor_enabled(): try: aug = get_augeas() except Exception: - # If there was an error with parsing or there are Deb822 - # files. + # If there was an error with parsing. return False for uri_path in iter_apt_uris(aug):