fix: handle read-only .git objects on Windows in shutil.rmtree calls#91
Open
ryanfk wants to merge 2 commits intomicrosoft:mainfrom
Open
fix: handle read-only .git objects on Windows in shutil.rmtree calls#91ryanfk wants to merge 2 commits intomicrosoft:mainfrom
ryanfk wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Git marks pack files and loose objects as read-only. On Windows this causes shutil.rmtree to raise [WinError 5] Access is denied when APM tries to remove a previously-cloned apm_modules directory or strip the .git folder after cloning. Add a _remove_readonly error handler that clears the read-only flag before retrying the delete, and wire it into every shutil.rmtree call in github_downloader.py. Fixes microsoft#90 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
On Windows, GitPython may hold file handles on .git objects after cloning. This causes shutil.rmtree to fail with [WinError 32] when cleaning up temporary directories. Extend _remove_readonly to handle WinError 32 by triggering gc.collect() to release GitPython handles, and explicitly close Repo objects before temp directory cleanup. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
apm_modulesdirectory or strip the.gitfolder after cloning,shutil.rmtreeraises[WinError 5] Access is denied._remove_readonlyerror handler that clears the read-only flag before retrying the delete.shutil.rmtreecalls ingithub_downloader.py, replacing both bare calls andignore_errors=True(which silently left files behind on Windows).Reproduction
Fix
Test plan
apm installnow succeeds after a previously failed install leaves read-only.gitobjects inapm_modules/onerrorhandler only triggers when the default delete fails, which doesn't happen on systems without read-only git objectsFixes #90
🤖 Generated with Claude Code