Project

General

Profile

« Previous | Next » 

Revision 866922f8

Added by koszko over 1 year ago

properly handle percent-encoded characters in .deb file names

View differences:

src/hydrilla/builder/local_apt.py
35 35
from pathlib import Path, PurePosixPath
36 36
from tempfile import TemporaryDirectory, NamedTemporaryFile
37 37
from hashlib import sha256
38
from urllib.parse import unquote
38 39
from contextlib import contextmanager
39 40
from typing import Optional, Iterable
40 41

  
......
296 297

  
297 298
    Return value is a list of names of all downloaded files.
298 299
    """
300
    install_line_regex = re.compile(r'^Inst (?P<name>\S+) \((?P<version>\S+) ')
301

  
299 302
    with local_apt(list, keys) as apt:
300 303
        if with_deps:
301 304
            cp = apt.get('install', '--yes', '--just-print', *packages)
302 305

  
303
            deps_listing = re.match(
304
                r'''
305
                .*
306
                The\sfollowing\sNEW\spackages\swill\sbe\sinstalled:
307
                (.*)
308
                0\supgraded,
309
                ''',
310
                cp.stdout,
311
                re.MULTILINE | re.DOTALL | re.VERBOSE)
306
            lines = cp.stdout.split('\n')
307
            matches = [install_line_regex.match(l) for l in lines]
308
            packages = [f'{m.group("name")}={m.group("version")}'
309
                        for m in matches if m]
312 310

  
313
            if deps_listing is None:
311
            if not packages:
314 312
                raise AptError(_('apt_install_output_not_understood'), cp)
315 313

  
316
            packages = deps_listing.group(1).split()
317

  
318 314
        # Download .debs to indirectly to destination_dir by first placing them
319 315
        # in a temporary subdirectory.
320 316
        with TemporaryDirectory(dir=destination_dir) as td:
......
343 339
                        .format(deb_file.name)
344 340
                    raise AptError(msg, cp)
345 341

  
346
                names_vers.append((match.group('name'), match.group('ver')))
342
                names_vers.append((
343
                    unquote(match.group('name')),
344
                    unquote(match.group('ver'))
345
                ))
347 346
                downloaded.append(deb_file.name)
348 347

  
349 348
            apt.get('source', '--download-only',

Also available in: Unified diff