Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
One approach to the symlink-following bug
  • Loading branch information
EliahKagan committed Nov 14, 2023
commit fd78a53f70a70c2ce8d891f8eb0692f4ab787e25
13 changes: 12 additions & 1 deletion git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def patch_env(name: str, value: str) -> Generator[None, None, None]:
os.environ[name] = old_value


def rmtree(path: PathLike) -> None:
def _rmtree_windows(path: PathLike) -> None:
"""Remove the given directory tree recursively.

:note: We use :func:`shutil.rmtree` but adjust its behaviour to see whether files
Expand Down Expand Up @@ -225,6 +225,17 @@ def handler(function: Callable, path: PathLike, _excinfo: Any) -> None:
shutil.rmtree(path, onerror=handler)


def _rmtree_posix(path: PathLike) -> None:
"""Remove the given directory tree recursively."""
return shutil.rmtree(path)


if os.name == "nt":
rmtree = _rmtree_windows
else:
rmtree = _rmtree_posix


def rmfile(path: PathLike) -> None:
"""Ensure file deleted also on *Windows* where read-only files need special treatment."""
if osp.isfile(path):
Expand Down