Skip to content

💫 Toolkit to help you get started with SDD or any other process!

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

Quratulain-bilal13f2b135cca4
diff --git a/src/specify_cli/extensions/__init__.py b/src/specify_cli/extensions/__init__.py
index 62f409fa8..354393b0d 100644
--- a/src/specify_cli/extensions/__init__.py
+++ b/src/specify_cli/extensions/__init__.py
@@ -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"):
diff --git a/src/specify_cli/integrations/_helpers.py b/src/specify_cli/integrations/_helpers.py
index 71b01d63c..2b7fc65db 100644
--- a/src/specify_cli/integrations/_helpers.py
+++ b/src/specify_cli/integrations/_helpers.py
@@ -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)
# ---------------------------------------------------------------------------