mirror of
https://github.com/borgbackup/borg.git
synced 2025-03-09 21:57:24 +00:00
Merge pull request #682 from ThomasWaldmann/validate-newname
add a simple archivename validator, fixes #680
This commit is contained in:
commit
fb83f619a0
2 changed files with 11 additions and 2 deletions
|
@ -15,7 +15,7 @@ import textwrap
|
|||
import traceback
|
||||
|
||||
from . import __version__
|
||||
from .helpers import Error, location_validator, format_time, format_file_size, \
|
||||
from .helpers import Error, location_validator, archivename_validator, format_time, format_file_size, \
|
||||
parse_pattern, PathPrefixPattern, to_localtime, timestamp, \
|
||||
get_cache_dir, get_keys_dir, prune_within, prune_split, \
|
||||
Manifest, remove_surrogates, update_excludes, format_archive, check_extension_modules, Statistics, \
|
||||
|
@ -1053,7 +1053,8 @@ class Archiver:
|
|||
subparser.add_argument('location', metavar='ARCHIVE',
|
||||
type=location_validator(archive=True),
|
||||
help='archive to rename')
|
||||
subparser.add_argument('name', metavar='NEWNAME', type=str,
|
||||
subparser.add_argument('name', metavar='NEWNAME',
|
||||
type=archivename_validator(),
|
||||
help='the new archive name to use')
|
||||
|
||||
delete_epilog = textwrap.dedent("""
|
||||
|
|
|
@ -757,6 +757,14 @@ def location_validator(archive=None):
|
|||
return validator
|
||||
|
||||
|
||||
def archivename_validator():
|
||||
def validator(text):
|
||||
if '/' in text or '::' in text or not text:
|
||||
raise argparse.ArgumentTypeError('Invalid repository name: "%s"' % text)
|
||||
return text
|
||||
return validator
|
||||
|
||||
|
||||
def decode_dict(d, keys, encoding='utf-8', errors='surrogateescape'):
|
||||
for key in keys:
|
||||
if isinstance(d.get(key), bytes):
|
||||
|
|
Loading…
Add table
Reference in a new issue