Skip to content

Make the rmtree callback Windows-only #1739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 15, 2023
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
Refactor current fix for symlink-following bug
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
commit 6de8e676c55170f073b64471e78b606c9c01b757
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