Skip to content

Commit

Permalink
Refactor current fix for symlink-following bug
Browse files Browse the repository at this point in the history
This keeps the same approach, but expresses it better. This does
not update the tests (yet), so one test is still failing.
  • Loading branch information
EliahKagan committed Nov 14, 2023
1 parent fd78a53 commit 6de8e67
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions 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_windows(path: PathLike) -> None:
def rmtree(path: PathLike) -> None:
"""Remove the given directory tree recursively.
:note: We use :func:`shutil.rmtree` but adjust its behaviour to see whether files
Expand All @@ -219,23 +219,14 @@ def handler(function: Callable, path: PathLike, _excinfo: Any) -> None:
raise SkipTest(f"FIXME: fails with: PermissionError\n {ex}") from ex
raise

if sys.version_info >= (3, 12):
if os.name != "nt":
shutil.rmtree(path)
elif sys.version_info >= (3, 12):
shutil.rmtree(path, onexc=handler)
else:
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 6de8e67

Please sign in to comment.