Skip to content

Commit d16351d

Browse files
Location: fix file URL parsing for windows
1 parent a9ef058 commit d16351d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/borg/helpers/parseformat.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from string import Formatter
1919

2020
from ..logger import create_logger
21+
from ..platformflags import is_windows
2122

2223
logger = create_logger()
2324

@@ -455,8 +456,9 @@ class Location:
455456
(?P<path>.+)
456457
"""
457458

458-
# abs_path must start with a slash.
459-
abs_path_re = r"(?P<path>/.+)"
459+
abs_path_re_posix = r"(?P<path>/.+)" # abs path must start with a slash.
460+
abs_path_re_win = r"(?P<path>[a-zA-Z]:/.+)" # abs path must start with drive : slash.
461+
abs_path_re = abs_path_re_win if is_windows else abs_path_re_posix
460462

461463
# path may or may not start with a slash.
462464
abs_or_rel_path_re = r"(?P<path>.+)"
@@ -495,7 +497,8 @@ class Location:
495497

496498
rclone_re = re.compile(r"(?P<proto>rclone):(?P<path>(.*))", re.VERBOSE)
497499

498-
file_or_socket_re = re.compile(r"(?P<proto>(file|socket))://" + abs_path_re, re.VERBOSE)
500+
sep = r"/" if is_windows else r"" # on windows, an addtl. slash is needed
501+
file_or_socket_re = re.compile(r"(?P<proto>(file|socket))://" + sep + abs_path_re, re.VERBOSE)
499502

500503
local_re = re.compile(local_path_re, re.VERBOSE)
501504

src/borg/platformflags.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
is_win32 = sys.platform.startswith("win32")
1010
is_cygwin = sys.platform.startswith("cygwin")
11+
is_msys = sys.platform.startswith("msys")
12+
is_windows = is_win32 or is_cygwin or is_msys
1113

1214
is_linux = sys.platform.startswith("linux")
1315
is_freebsd = sys.platform.startswith("freebsd")

0 commit comments

Comments
 (0)