Repository navigation
Use a special technique to remove git repos on Windows - #442
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds a Windows-aware smart_rmtree to clear read-only flags before deletion, switches clone to use it, and documents the fix in the changelog.
- Introduce
smart_rmtreeinbench_runner/util.pyto handle read-only files on Windows - Update
bench_runner/git.pyto callutil.smart_rmtreeinstead ofshutil.rmtree - Record the Windows fix in
CHANGELOG.md
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| bench_runner/util.py | Add smart_rmtree variants for Windows and default fallback |
| bench_runner/git.py | Replace shutil.rmtree with util.smart_rmtree in clone |
| CHANGELOG.md | Add entry for Windows repo-removal bugfix |
Comments suppressed due to low confidence (3)
bench_runner/util.py:112
- We should add a test to verify that
smart_rmtreecorrectly removes directories containing read-only files on Windows platforms.
def smart_rmtree(path: PathLike) -> None:
bench_runner/util.py:115
- The code calls
os.accessandos.chmodbutosis not imported in this file, leading to a NameError. Addimport osat the top.
if not os.access(path, os.W_OK):
bench_runner/util.py:132
- The handler references undefined name
exc. It should use theerrorparameter (e.g.raise error[1]).
raise exc[1]
Comment on lines
+110
to
+135
| if sys.version_info >= (3, 12): | ||
|
|
||
| def smart_rmtree(path: PathLike) -> None: | ||
| def onexc(func, path, exc): | ||
| # Is the error an access error? | ||
| if not os.access(path, os.W_OK): | ||
| os.chmod(path, stat.S_IWUSR) | ||
| func(path) | ||
| else: | ||
| raise exc | ||
|
|
||
| shutil.rmtree(path, onexc=onexc) | ||
|
|
||
| else: | ||
|
|
||
| def smart_rmtree(path: PathLike) -> None: | ||
| def onerror(func, path, error): | ||
| # Is the error an access error? | ||
| if not os.access(path, os.W_OK): | ||
| os.chmod(path, stat.S_IWUSR) | ||
| func(path) | ||
| else: | ||
| raise exc[1] | ||
|
|
||
| shutil.rmtree(path, onerror=onerror) | ||
|
|
There was a problem hiding this comment.
[nitpick] The Windows-specific smart_rmtree logic is duplicated for pre-3.12 and post-3.12 branches. Consider extracting shared code into a single helper to reduce duplication.
Suggested change
| if sys.version_info >= (3, 12): | |
| def smart_rmtree(path: PathLike) -> None: | |
| def onexc(func, path, exc): | |
| # Is the error an access error? | |
| if not os.access(path, os.W_OK): | |
| os.chmod(path, stat.S_IWUSR) | |
| func(path) | |
| else: | |
| raise exc | |
| shutil.rmtree(path, onexc=onexc) | |
| else: | |
| def smart_rmtree(path: PathLike) -> None: | |
| def onerror(func, path, error): | |
| # Is the error an access error? | |
| if not os.access(path, os.W_OK): | |
| os.chmod(path, stat.S_IWUSR) | |
| func(path) | |
| else: | |
| raise exc[1] | |
| shutil.rmtree(path, onerror=onerror) | |
| def handle_access_error(func, path, exc_info): | |
| # Is the error an access error? | |
| if not os.access(path, os.W_OK): | |
| os.chmod(path, stat.S_IWUSR) | |
| func(path) | |
| else: | |
| raise exc_info[1] if isinstance(exc_info, tuple) else exc_info | |
| def smart_rmtree(path: PathLike) -> None: | |
| if sys.version_info >= (3, 12): | |
| shutil.rmtree(path, onexc=lambda func, path, exc: handle_access_error(func, path, exc)) | |
| else: | |
| shutil.rmtree(path, onerror=lambda func, path, error: handle_access_error(func, path, error)) |
mdboom
force-pushed
the
windows-git-rmtree
branch
from
June 5, 2025 15:31
0ca860b to
46e3954
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.