Skip to content

Commit

Permalink
long path fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tor Colvin authored and Tor Colvin committed Feb 17, 2020
1 parent d18c75b commit 33aef22
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/_pytest/pathlib.py
Expand Up @@ -99,11 +99,18 @@ def chmod_rw(p: str) -> None:
func(path)
return True

def create_long_path(path: Path) -> Path:
if sys.platform.startswith("win32"):
path = path.resolve()
if not str(path).startswith(r"\\?"):
path = Path(r"\\?" + str(path))
return path

def rm_rf(path: Path) -> None:
"""Remove the path contents recursively, even if some elements
are read-only.
"""
path = create_long_path(path)
onerror = partial(on_rm_rf_error, start_path=path)
shutil.rmtree(str(path), onerror=onerror)

Expand Down
12 changes: 12 additions & 0 deletions testing/test_pathlib.py
Expand Up @@ -89,3 +89,15 @@ def renamed_failed(*args):
lock_path = get_lock_path(path)
maybe_delete_a_numbered_dir(path)
assert not lock_path.is_file()

def test_long_path_during_cleanup(tmp_path):
"""Ensure that deleting long path will be able to be deleted"""
path = tmp_path / ("a" * 200)
if sys.platform == "win32":
dirname = path.resolve()
dirname = "\\\\?\\" + str(path)
os.mkdir(dirname)

lock_path = get_lock_path(path)
maybe_delete_a_numbered_dir(path)
assert not lock_path.is_file()

0 comments on commit 33aef22

Please sign in to comment.