-
Notifications
You must be signed in to change notification settings - Fork 7
Use a special technique to remove git repos on Windows #442
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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]
| 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) | ||
|
|
Copilot
AI
Jun 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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.
| 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)) |
0ca860b to
46e3954
Compare
No description provided.