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 <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2022-11-19 19:56:26 -05:00 committed by Sunil Mohan Adapa
parent cd21c7f247
commit 25d32d245a
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2

View File

@ -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):