diff --git a/src/borg/archiver/create_cmd.py b/src/borg/archiver/create_cmd.py index 741e363c5..d56a700f6 100644 --- a/src/borg/archiver/create_cmd.py +++ b/src/borg/archiver/create_cmd.py @@ -15,7 +15,7 @@ from ..archive import FilesystemObjectProcessors, MetadataCollector, ChunksProce from ..cache import Cache from ..constants import * # NOQA from ..compress import CompressionSpec -from ..helpers import ChunkerParams +from ..helpers import comment_validator, ChunkerParams from ..helpers import NameSpec, FilesCacheMode from ..helpers import eval_escapes from ..helpers import timestamp, archive_ts_now @@ -811,7 +811,12 @@ class CreateMixIn: archive_group = subparser.add_argument_group("Archive options") archive_group.add_argument( - "--comment", dest="comment", metavar="COMMENT", default="", help="add a comment text to the archive" + "--comment", + metavar="COMMENT", + dest="comment", + type=comment_validator, + default="", + help="add a comment text to the archive", ) archive_group.add_argument( "--timestamp", diff --git a/src/borg/archiver/recreate_cmd.py b/src/borg/archiver/recreate_cmd.py index 40f2d6f26..c4d707e13 100644 --- a/src/borg/archiver/recreate_cmd.py +++ b/src/borg/archiver/recreate_cmd.py @@ -5,7 +5,7 @@ from ._common import build_matcher from ..archive import ArchiveRecreater from ..constants import * # NOQA from ..compress import CompressionSpec -from ..helpers import archivename_validator, ChunkerParams +from ..helpers import archivename_validator, comment_validator, ChunkerParams from ..helpers import timestamp from ..manifest import Manifest @@ -161,7 +161,12 @@ class RecreateMixIn: help="write checkpoint every SECONDS seconds (Default: 1800)", ) archive_group.add_argument( - "--comment", dest="comment", metavar="COMMENT", default=None, help="add a comment text to the archive" + "--comment", + metavar="COMMENT", + dest="comment", + type=comment_validator, + default=None, + help="add a comment text to the archive", ) archive_group.add_argument( "--timestamp", diff --git a/src/borg/archiver/tar_cmds.py b/src/borg/archiver/tar_cmds.py index c08c50b8f..9e9dc5162 100644 --- a/src/borg/archiver/tar_cmds.py +++ b/src/borg/archiver/tar_cmds.py @@ -15,7 +15,7 @@ from ..helpers import dash_open from ..helpers import msgpack from ..helpers import create_filter_process from ..helpers import ChunkIteratorFileWrapper -from ..helpers import ChunkerParams +from ..helpers import comment_validator, ChunkerParams from ..helpers import NameSpec from ..helpers import remove_surrogates from ..helpers import timestamp, archive_ts_now @@ -491,7 +491,12 @@ class TarMixIn: archive_group = subparser.add_argument_group("Archive options") archive_group.add_argument( - "--comment", dest="comment", metavar="COMMENT", default="", help="add a comment text to the archive" + "--comment", + metavar="COMMENT", + dest="comment", + type=comment_validator, + default="", + help="add a comment text to the archive", ) archive_group.add_argument( "--timestamp", diff --git a/src/borg/archiver/transfer_cmd.py b/src/borg/archiver/transfer_cmd.py index bc6718e25..0c26bdf73 100644 --- a/src/borg/archiver/transfer_cmd.py +++ b/src/borg/archiver/transfer_cmd.py @@ -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, archivename_validator +from ..helpers import location_validator, Location, archivename_validator, comment_validator from ..helpers import format_file_size from ..manifest import Manifest @@ -52,6 +52,19 @@ class TransferMixIn: self.print_error(err_msg) return EXIT_ERROR + ac_errors = [] + for archive_name in archive_names: + archive = Archive(other_manifest, archive_name) + try: + comment_validator(archive.metadata.get("comment", "")) + except argparse.ArgumentTypeError as err: + ac_errors.append((archive_name, str(err))) + if ac_errors: + self.print_error("Invalid archive comments detected, please fix them before transfer:") + for archive_name, err_msg in ac_errors: + self.print_error(f"{archive_name}: {err_msg}") + return EXIT_ERROR + from .. import upgrade as upgrade_mod try: