aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-05-11 10:23:59 +0200
committerWojtek Kosior <koszko@koszko.org>2022-05-11 10:23:59 +0200
commit866922f80326671815c9187eed0ba6c4127b8721 (patch)
tree3d1b15fc432c070ca322347cc2fe882d6fc1fe66 /src/hydrilla
parentbd588eb9a4b2890da6f9db928f302e2e98a7b9ce (diff)
downloadhydrilla-builder-866922f80326671815c9187eed0ba6c4127b8721.tar.gz
hydrilla-builder-866922f80326671815c9187eed0ba6c4127b8721.zip
properly handle percent-encoded characters in .deb file names
Diffstat (limited to 'src/hydrilla')
-rw-r--r--src/hydrilla/builder/local_apt.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/hydrilla/builder/local_apt.py b/src/hydrilla/builder/local_apt.py
index 4c93a4d..eee028d 100644
--- a/src/hydrilla/builder/local_apt.py
+++ b/src/hydrilla/builder/local_apt.py
@@ -35,6 +35,7 @@ CP = subprocess.CompletedProcess
from pathlib import Path, PurePosixPath
from tempfile import TemporaryDirectory, NamedTemporaryFile
from hashlib import sha256
+from urllib.parse import unquote
from contextlib import contextmanager
from typing import Optional, Iterable
@@ -296,25 +297,20 @@ def download_apt_packages(list: SourcesList, keys: [str], packages: [str],
Return value is a list of names of all downloaded files.
"""
+ install_line_regex = re.compile(r'^Inst (?P<name>\S+) \((?P<version>\S+) ')
+
with local_apt(list, keys) as apt:
if with_deps:
cp = apt.get('install', '--yes', '--just-print', *packages)
- deps_listing = re.match(
- r'''
- .*
- The\sfollowing\sNEW\spackages\swill\sbe\sinstalled:
- (.*)
- 0\supgraded,
- ''',
- cp.stdout,
- re.MULTILINE | re.DOTALL | re.VERBOSE)
+ lines = cp.stdout.split('\n')
+ matches = [install_line_regex.match(l) for l in lines]
+ packages = [f'{m.group("name")}={m.group("version")}'
+ for m in matches if m]
- if deps_listing is None:
+ if not packages:
raise AptError(_('apt_install_output_not_understood'), cp)
- packages = deps_listing.group(1).split()
-
# Download .debs to indirectly to destination_dir by first placing them
# in a temporary subdirectory.
with TemporaryDirectory(dir=destination_dir) as td:
@@ -343,7 +339,10 @@ def download_apt_packages(list: SourcesList, keys: [str], packages: [str],
.format(deb_file.name)
raise AptError(msg, cp)
- names_vers.append((match.group('name'), match.group('ver')))
+ names_vers.append((
+ unquote(match.group('name')),
+ unquote(match.group('ver'))
+ ))
downloaded.append(deb_file.name)
apt.get('source', '--download-only',