diff --git a/src/borg/helpers/fs.py b/src/borg/helpers/fs.py index 68f0cd69f..14af58931 100644 --- a/src/borg/helpers/fs.py +++ b/src/borg/helpers/fs.py @@ -1,7 +1,7 @@ import errno import hashlib import os -import os.path +import posixpath import re import stat import subprocess @@ -231,7 +231,7 @@ def make_path_safe(path): path = path.lstrip("/") if path.startswith("../") or "/../" in path or path.endswith("/..") or path == "..": raise ValueError(f"unexpected '..' element in path {path!r}") - path = os.path.normpath(path) + path = posixpath.normpath(path) return path @@ -245,6 +245,11 @@ def remove_dotdot_prefixes(path): `path` is expected to be normalized already (e.g. via `os.path.normpath()`). """ + if is_win32: + if len(path) > 1 and path[1] == ":": + path = path.replace(":", "", 1) + path = path.replace("\\", "/") + path = path.lstrip("/") path = _dotdot_re.sub("", path) if path in ["", ".."]: diff --git a/src/borg/testsuite/archiver/create_cmd.py b/src/borg/testsuite/archiver/create_cmd.py index cd80ea486..bf9f9c71d 100644 --- a/src/borg/testsuite/archiver/create_cmd.py +++ b/src/borg/testsuite/archiver/create_cmd.py @@ -103,15 +103,14 @@ def filter(output): # the interesting parts of info_output2 and info_output should be same self.assert_equal(filter(info_output), filter(info_output2)) - @pytest.mark.skipif(is_win32, reason="still broken on windows") def test_archived_paths(self): # As borg comes from the POSIX (Linux, UNIX) world, a lot of stuff assumes path separators # to be slashes "/", e.g.: in archived items, for pattern matching. # To make our lives easier and to support cross-platform extraction we always use slashes. # Similarly, archived paths are expected to be full, but relative (have no leading slash). full_path = os.path.abspath(os.path.join(self.input_path, "test")) - # remove windows drive letter, if any: - posix_path = full_path[2:] if full_path[1] == ":" else full_path + # remove colon from windows drive letter, if any: + posix_path = full_path.replace(":", "") if full_path[1] == ":" else full_path # only needed on windows in case there are backslashes: posix_path = posix_path.replace("\\", "/") # no leading slash in borg archives: