Merge pull request #9313 from trxvorr/fix-9279-drive-letters

windows: normalize drive letters fixes #9279
This commit is contained in:
TW 2026-02-14 18:55:44 +01:00 committed by GitHub
commit e60874ecbd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 0 deletions

View file

@ -252,6 +252,12 @@ def make_path_safe(path):
if "\\.." in path or "..\\" in path:
raise ValueError(f"unexpected '..' element in path {path!r}")
path = slashify(path)
if is_win32 and len(path) >= 2 and path[1] == ":":
# Handle drive letters: C:/path -> C/path
path = path[0].upper() + path[2:]
path = map_chars(path)
path = path.lstrip("/")

View file

@ -318,6 +318,23 @@ def test_invalid_make_path_safe(path):
make_path_safe(path)
def test_make_path_safe_win32_drive_letters(monkeypatch):
monkeypatch.setattr("borg.helpers.fs.is_win32", True)
# Basic drive letter
assert make_path_safe("C:\\Users") == "C/Users"
assert make_path_safe("C:\\Users\\test") == "C/Users/test"
# Lowercase drive letter -> Uppercase
assert make_path_safe("c:\\windows") == "C/windows"
# Relative path with backslashes
assert make_path_safe("foo\\bar") == "foo/bar"
# Just drive letter
assert make_path_safe("D:") == "D"
# Drive letter with forward slash
assert make_path_safe("E:/test") == "E/test"
# Mixed separators
assert make_path_safe("F:\\Mixed/Separators") == "F/Mixed/Separators"
def test_dir_is_tagged(tmpdir):
"""Test dir_is_tagged with both path-based and file descriptor-based operations."""