Skip to content

fix: handle read-only .git files in deploy cleanup on Windows#4719

Open
OiPunk wants to merge 1 commit intogoogle:mainfrom
OiPunk:codex/adk-4635-windows-rmtree-readonly
Open

fix: handle read-only .git files in deploy cleanup on Windows#4719
OiPunk wants to merge 1 commit intogoogle:mainfrom
OiPunk:codex/adk-4635-windows-rmtree-readonly

Conversation

@OiPunk
Copy link

@OiPunk OiPunk commented Mar 5, 2026

Summary

Fixes #4635

On Windows, files inside .git/objects/ are marked read-only by default. When adk deploy cleans up the temporary directory in its finally block, shutil.rmtree() raises PermissionError: [WinError 5] Access denied on these files, causing the CLI to crash even after a successful deployment.

This PR introduces a _robust_rmtree() helper that passes an error handler to shutil.rmtree. On Windows, the handler clears the read-only bit (os.chmod(path, stat.S_IWRITE)) and retries the deletion. On non-Windows platforms, shutil.rmtree is called without any handler. The fix uses onexc for Python >= 3.12 and onerror for Python < 3.12 to avoid deprecation warnings.

All six shutil.rmtree() call sites in cli_deploy.py (to_cloud_run, to_agent_engine, to_gke) are updated.

Test Plan

  • Added TestRobustRmtree with three unit tests:
    • test_removes_directory_tree -- verifies normal directory removal
    • test_removes_readonly_files -- verifies removal of trees containing read-only files
    • test_on_rm_error_clears_readonly_and_retries -- verifies the error handler chmod + retry logic
  • All 33 existing + new tests pass: pytest tests/unittests/cli/utils/test_cli_deploy.py

… cleanup

Replace all bare shutil.rmtree() calls in cli_deploy.py with a
_robust_rmtree() helper that clears the read-only bit before
retrying deletion on Windows. This prevents PermissionError
([WinError 5]) when cleaning up .git/objects after deployment.

The fix is compatible with Python 3.10+ (uses onerror for <3.12
and onexc for >=3.12).
@gemini-code-assist
Copy link
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@adk-bot adk-bot added the tools [Component] This issue is related to tools label Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools [Component] This issue is related to tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Windows] adk deploy fails with [WinError 5] during cleanup of .git repositories

2 participants