mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-27 02:08:54 +00:00
Merge pull request #7676 from RayyanAnsari/paths-win
Properly normalise paths on Windows
This commit is contained in:
commit
cfbfe2423f
2 changed files with 9 additions and 5 deletions
|
@ -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 ["", ".."]:
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue