mirror of https://github.com/borgbackup/borg.git
add a simple archivename validator, fixes #680
This commit is contained in:
parent
a44c1f5092
commit
4a60d777d8
|
@ -15,7 +15,7 @@ import textwrap
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from . import __version__
|
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, \
|
parse_pattern, PathPrefixPattern, to_localtime, timestamp, \
|
||||||
get_cache_dir, get_keys_dir, prune_within, prune_split, \
|
get_cache_dir, get_keys_dir, prune_within, prune_split, \
|
||||||
Manifest, remove_surrogates, update_excludes, format_archive, check_extension_modules, Statistics, \
|
Manifest, remove_surrogates, update_excludes, format_archive, check_extension_modules, Statistics, \
|
||||||
|
@ -1050,7 +1050,8 @@ class Archiver:
|
||||||
subparser.add_argument('location', metavar='ARCHIVE',
|
subparser.add_argument('location', metavar='ARCHIVE',
|
||||||
type=location_validator(archive=True),
|
type=location_validator(archive=True),
|
||||||
help='archive to rename')
|
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')
|
help='the new archive name to use')
|
||||||
|
|
||||||
delete_epilog = textwrap.dedent("""
|
delete_epilog = textwrap.dedent("""
|
||||||
|
|
|
@ -757,6 +757,14 @@ def location_validator(archive=None):
|
||||||
return validator
|
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'):
|
def decode_dict(d, keys, encoding='utf-8', errors='surrogateescape'):
|
||||||
for key in keys:
|
for key in keys:
|
||||||
if isinstance(d.get(key), bytes):
|
if isinstance(d.get(key), bytes):
|
||||||
|
|
Loading…
Reference in New Issue