Commit c93fcc0
fix: handle read-only .git files in deploy cleanup on Windows
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.
Fixes #4635
Merge #4719
PiperOrigin-RevId: 9643923311 parent 69c9090 commit c93fcc0
2 files changed
Lines changed: 66 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
45 | 63 | | |
46 | 64 | | |
47 | 65 | | |
| |||
717 | 735 | | |
718 | 736 | | |
719 | 737 | | |
720 | | - | |
| 738 | + | |
721 | 739 | | |
722 | 740 | | |
723 | 741 | | |
| |||
839 | 857 | | |
840 | 858 | | |
841 | 859 | | |
842 | | - | |
| 860 | + | |
843 | 861 | | |
844 | 862 | | |
845 | 863 | | |
| |||
997 | 1015 | | |
998 | 1016 | | |
999 | 1017 | | |
1000 | | - | |
| 1018 | + | |
1001 | 1019 | | |
1002 | 1020 | | |
1003 | 1021 | | |
| |||
1308 | 1326 | | |
1309 | 1327 | | |
1310 | 1328 | | |
1311 | | - | |
| 1329 | + | |
1312 | 1330 | | |
1313 | 1331 | | |
1314 | 1332 | | |
| |||
1387 | 1405 | | |
1388 | 1406 | | |
1389 | 1407 | | |
1390 | | - | |
| 1408 | + | |
1391 | 1409 | | |
1392 | 1410 | | |
1393 | 1411 | | |
| |||
1558 | 1576 | | |
1559 | 1577 | | |
1560 | 1578 | | |
1561 | | - | |
| 1579 | + | |
1562 | 1580 | | |
1563 | 1581 | | |
1564 | 1582 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1164 | 1164 | | |
1165 | 1165 | | |
1166 | 1166 | | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
0 commit comments