transfer: validate archive names before transfer

This commit is contained in:
Thomas Waldmann 2022-12-10 15:05:58 +01:00
parent fe2b2bc007
commit ebff12ad41
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01

View file

@ -5,7 +5,7 @@ from ..archive import Archive
from ..constants import * # NOQA
from ..crypto.key import uses_same_id_hash, uses_same_chunker_secret
from ..helpers import EXIT_SUCCESS, EXIT_ERROR, Error
from ..helpers import location_validator, Location
from ..helpers import location_validator, Location, archivename_validator
from ..helpers import format_file_size
from ..manifest import Manifest
@ -39,6 +39,19 @@ class TransferMixIn:
if not archive_names:
return EXIT_SUCCESS
an_errors = []
av = archivename_validator()
for archive_name in archive_names:
try:
av(archive_name)
except argparse.ArgumentTypeError as err:
an_errors.append(str(err))
if an_errors:
self.print_error("Invalid archive names detected, please rename them before transfer:")
for err_msg in an_errors:
self.print_error(err_msg)
return EXIT_ERROR
from .. import upgrade as upgrade_mod
try: