diff options
author | Antti Aalto <antti.aalto.10@gmail.com> | 2017-10-30 17:21:44 +0200 |
---|---|---|
committer | Antti Aalto <antti.aalto.10@gmail.com> | 2017-10-30 17:21:44 +0200 |
commit | 38d2f1efd644f71e000146230520ddc0369955d3 (patch) | |
tree | 0c7676c71f363e3c4c46c726f885d4977ba0d44b | |
parent | 248eb605b6b96e86092193e768b816dd2c5ce682 (diff) |
Fix windows absolute paths.
-rw-r--r-- | src/borg/helpers/parseformat.py | 69 |
1 files changed, 45 insertions, 24 deletions
diff --git a/src/borg/helpers/parseformat.py b/src/borg/helpers/parseformat.py index a4115baef..a2dec2c3f 100644 --- a/src/borg/helpers/parseformat.py +++ b/src/borg/helpers/parseformat.py @@ -25,6 +25,8 @@ from .. import __version__ as borg_version from .. import __version_tuple__ as borg_version_tuple from ..constants import * # NOQA +if sys.platform == 'win32': + import posixpath def bin_to_hex(binary): return hexlify(binary).decode('ascii') @@ -362,6 +364,8 @@ class Location: | # or """ + optional_archive_re, re.VERBOSE) # archive name (optional, may be empty) + win_file_re = re.compile(r'(?:file://)?(?P<path>(?:[a-zA-Z]:[\\/])?(?:[^:]*))' + optional_archive_re, re.VERBOSE) + def __init__(self, text=''): self.orig = text if not self.parse(self.orig): @@ -390,30 +394,47 @@ class Location: relative = p.startswith('/./') p = os.path.normpath(p) return ('/.' + p) if relative else p - - m = self.ssh_re.match(text) - if m: - self.proto = m.group('proto') - self.user = m.group('user') - self._host = m.group('host') - self.port = m.group('port') and int(m.group('port')) or None - self.path = normpath_special(m.group('path')) - self.archive = m.group('archive') - return True - m = self.file_re.match(text) - if m: - self.proto = m.group('proto') - self.path = normpath_special(m.group('path')) - self.archive = m.group('archive') - return True - m = self.scp_re.match(text) - if m: - self.user = m.group('user') - self._host = m.group('host') - self.path = normpath_special(m.group('path')) - self.archive = m.group('archive') - self.proto = self._host and 'ssh' or 'file' - return True + if sys.platform != 'win32': + m = self.ssh_re.match(text) + if m: + self.proto = m.group('proto') + self.user = m.group('user') + self._host = m.group('host') + self.port = m.group('port') and int(m.group('port')) or None + self.path = normpath_special(m.group('path')) + self.archive = m.group('archive') + return True + m = self.file_re.match(text) + if m: + self.proto = m.group('proto') + self.path = normpath_special(m.group('path')) + self.archive = m.group('archive') + return True + m = self.scp_re.match(text) + if m: + self.user = m.group('user') + self._host = m.group('host') + self.path = normpath_special(m.group('path')) + self.archive = m.group('archive') + self.proto = self._host and 'ssh' or 'file' + return True + else: + m = self.win_file_re.match(text) + if m: + self.proto = 'file' + self.path = posixpath.normpath(m.group('path')) + self.archive = m.group('archive') + return True + m = self.ssh_re.match(text) + if m: + self.proto = m.group('proto') + self.user = m.group('user') + self._host = m.group('host') + self.port = m.group('port') and int(m.group('port')) or None + self.path = normpath_special(m.group('path')) + self.archive = m.group('archive') + return True + return False def __str__(self): |