fix: eliminate TOCTOU race in file unlink calls (#3811)

This commit is contained in:
Quratulain-bilal
2026-07-29 20:36:40 +05:00
committed by GitHub
parent 54396780f3
commit 13f2b135cc
2 changed files with 3 additions and 6 deletions

View File

@@ -3895,10 +3895,8 @@ class ExtensionCatalog(CatalogStackBase):
def clear_cache(self):
"""Clear the catalog cache (both legacy and URL-hash-based files)."""
if self.cache_file.exists():
self.cache_file.unlink()
if self.cache_metadata_file.exists():
self.cache_metadata_file.unlink()
self.cache_file.unlink(missing_ok=True)
self.cache_metadata_file.unlink(missing_ok=True)
# Also clear any per-URL hash-based cache files
if self.cache_dir.exists():
for extra_cache in self.cache_dir.glob("catalog-*.json"):

View File

@@ -121,8 +121,7 @@ def _clear_init_options_for_integration(project_root: Path, integration_key: str
def _remove_integration_json(project_root: Path) -> None:
"""Remove ``.specify/integration.json`` if it exists."""
path = project_root / INTEGRATION_JSON
if path.exists():
path.unlink()
path.unlink(missing_ok=True)
# ---------------------------------------------------------------------------