mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-25 07:23:28 +00:00
use comment validator for cli args and borg transfer
This commit is contained in:
parent
99c6afbc61
commit
4b54b5565e
4 changed files with 35 additions and 7 deletions
|
@ -15,7 +15,7 @@
|
|||
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 @@ def build_parser_create(self, subparsers, common_parser, mid_common_parser):
|
|||
|
||||
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",
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
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 @@ def build_parser_recreate(self, subparsers, common_parser, mid_common_parser):
|
|||
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",
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
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 @@ def build_parser_tar(self, subparsers, common_parser, mid_common_parser):
|
|||
|
||||
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",
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
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 @@ def do_transfer(self, args, *, repository, manifest, cache, other_repository=Non
|
|||
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:
|
||||
|
|
Loading…
Reference in a new issue