Skip to content

Commit 6de8e67

Browse files
committed
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.
1 parent fd78a53 commit 6de8e67

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

git/util.py

+4-13
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def patch_env(name: str, value: str) -> Generator[None, None, None]:
197197
os.environ[name] = old_value
198198

199199

200-
def _rmtree_windows(path: PathLike) -> None:
200+
def rmtree(path: PathLike) -> None:
201201
"""Remove the given directory tree recursively.
202202
203203
:note: We use :func:`shutil.rmtree` but adjust its behaviour to see whether files
@@ -219,23 +219,14 @@ def handler(function: Callable, path: PathLike, _excinfo: Any) -> None:
219219
raise SkipTest(f"FIXME: fails with: PermissionError\n {ex}") from ex
220220
raise
221221

222-
if sys.version_info >= (3, 12):
222+
if os.name != "nt":
223+
shutil.rmtree(path)
224+
elif sys.version_info >= (3, 12):
223225
shutil.rmtree(path, onexc=handler)
224226
else:
225227
shutil.rmtree(path, onerror=handler)
226228

227229

228-
def _rmtree_posix(path: PathLike) -> None:
229-
"""Remove the given directory tree recursively."""
230-
return shutil.rmtree(path)
231-
232-
233-
if os.name == "nt":
234-
rmtree = _rmtree_windows
235-
else:
236-
rmtree = _rmtree_posix
237-
238-
239230
def rmfile(path: PathLike) -> None:
240231
"""Ensure file deleted also on *Windows* where read-only files need special treatment."""
241232
if osp.isfile(path):

0 commit comments

Comments
 (0)