Skip to content

Commit e60874e

Browse files
Merge pull request #9313 from trxvorr/fix-9279-drive-letters
windows: normalize drive letters fixes #9279
2 parents b9d6369 + 6430564 commit e60874e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/borg/helpers/fs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ def make_path_safe(path):
252252
if "\\.." in path or "..\\" in path:
253253
raise ValueError(f"unexpected '..' element in path {path!r}")
254254

255+
path = slashify(path)
256+
257+
if is_win32 and len(path) >= 2 and path[1] == ":":
258+
# Handle drive letters: C:/path -> C/path
259+
path = path[0].upper() + path[2:]
260+
255261
path = map_chars(path)
256262

257263
path = path.lstrip("/")

src/borg/testsuite/helpers/fs_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,23 @@ def test_invalid_make_path_safe(path):
318318
make_path_safe(path)
319319

320320

321+
def test_make_path_safe_win32_drive_letters(monkeypatch):
322+
monkeypatch.setattr("borg.helpers.fs.is_win32", True)
323+
# Basic drive letter
324+
assert make_path_safe("C:\\Users") == "C/Users"
325+
assert make_path_safe("C:\\Users\\test") == "C/Users/test"
326+
# Lowercase drive letter -> Uppercase
327+
assert make_path_safe("c:\\windows") == "C/windows"
328+
# Relative path with backslashes
329+
assert make_path_safe("foo\\bar") == "foo/bar"
330+
# Just drive letter
331+
assert make_path_safe("D:") == "D"
332+
# Drive letter with forward slash
333+
assert make_path_safe("E:/test") == "E/test"
334+
# Mixed separators
335+
assert make_path_safe("F:\\Mixed/Separators") == "F/Mixed/Separators"
336+
337+
321338
def test_dir_is_tagged(tmpdir):
322339
"""Test dir_is_tagged with both path-based and file descriptor-based operations."""
323340

0 commit comments

Comments
 (0)