use comment validator for cli args and borg transfer

This commit is contained in:
Thomas Waldmann 2022-12-12 18:48:01 +01:00
parent 99c6afbc61
commit 4b54b5565e
No known key found for this signature in database
GPG Key ID: 243ACFA951F78E01
4 changed files with 35 additions and 7 deletions

View File

@ -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",

View File

@ -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",

View File

@ -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",

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, 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: