mirror of https://github.com/borgbackup/borg.git
Merge pull request #211 from ThomasWaldmann/archivename_validation
archive names with slashes are invalid, attic issue #180
This commit is contained in:
commit
44d1a32e60
|
@ -718,7 +718,7 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
|
|||
help='do not create a backup archive')
|
||||
subparser.add_argument('archive', metavar='ARCHIVE',
|
||||
type=location_validator(archive=True),
|
||||
help='archive to create')
|
||||
help='name of archive to create (must be also a valid directory name)')
|
||||
subparser.add_argument('paths', metavar='PATH', nargs='+', type=str,
|
||||
help='paths to archive')
|
||||
|
||||
|
|
|
@ -490,18 +490,20 @@ class Location:
|
|||
"""Object representing a repository / archive location
|
||||
"""
|
||||
proto = user = host = port = path = archive = None
|
||||
# borg mount's FUSE filesystem creates one level of directories from
|
||||
# the archive names. Thus, we must not accept "/" in archive names.
|
||||
ssh_re = re.compile(r'(?P<proto>ssh)://(?:(?P<user>[^@]+)@)?'
|
||||
r'(?P<host>[^:/#]+)(?::(?P<port>\d+))?'
|
||||
r'(?P<path>[^:]+)(?:::(?P<archive>.+))?$')
|
||||
r'(?P<path>[^:]+)(?:::(?P<archive>[^/]+))?$')
|
||||
file_re = re.compile(r'(?P<proto>file)://'
|
||||
r'(?P<path>[^:]+)(?:::(?P<archive>.+))?$')
|
||||
r'(?P<path>[^:]+)(?:::(?P<archive>[^/]+))?$')
|
||||
scp_re = re.compile(r'((?:(?P<user>[^@]+)@)?(?P<host>[^:/]+):)?'
|
||||
r'(?P<path>[^:]+)(?:::(?P<archive>.+))?$')
|
||||
r'(?P<path>[^:]+)(?:::(?P<archive>[^/]+))?$')
|
||||
# get the repo from BORG_RE env and the optional archive from param.
|
||||
# if the syntax requires giving REPOSITORY (see "borg mount"),
|
||||
# use "::" to let it use the env var.
|
||||
# if REPOSITORY argument is optional, it'll automatically use the env.
|
||||
env_re = re.compile(r'(?:::(?P<archive>.+)?)?$')
|
||||
env_re = re.compile(r'(?:::(?P<archive>[^/]+)?)?$')
|
||||
|
||||
def __init__(self, text=''):
|
||||
self.orig = text
|
||||
|
|
|
@ -81,6 +81,11 @@ class TestLocationWithoutEnv:
|
|||
with pytest.raises(ValueError):
|
||||
Location('ssh://localhost:22/path:archive')
|
||||
|
||||
def test_no_slashes(self, monkeypatch):
|
||||
monkeypatch.delenv('BORG_REPO', raising=False)
|
||||
with pytest.raises(ValueError):
|
||||
Location('/some/path/to/repo::archive_name_with/slashes/is_invalid')
|
||||
|
||||
def test_canonical_path(self, monkeypatch):
|
||||
monkeypatch.delenv('BORG_REPO', raising=False)
|
||||
locations = ['some/path::archive', 'file://some/path::archive', 'host:some/path::archive',
|
||||
|
@ -134,6 +139,11 @@ class TestLocationWithEnv:
|
|||
assert repr(Location()) == \
|
||||
"Location(proto='file', user=None, host=None, port=None, path='some/relative/path', archive=None)"
|
||||
|
||||
def test_no_slashes(self, monkeypatch):
|
||||
monkeypatch.setenv('BORG_REPO', '/some/absolute/path')
|
||||
with pytest.raises(ValueError):
|
||||
Location('::archive_name_with/slashes/is_invalid')
|
||||
|
||||
|
||||
class FormatTimedeltaTestCase(BaseTestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue