Skip to content

Commit

Permalink
One approach to the symlink-following bug
Browse files Browse the repository at this point in the history
  • Loading branch information
EliahKagan committed Nov 14, 2023
1 parent 5335416 commit fd78a53
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit fd78a53

Please sign in to comment.