From d5fe7d828ed85279d6ede7988d93d8a38302685a Mon Sep 17 00:00:00 2001 From: Quratulain-bilal Date: Wed, 29 Jul 2026 00:27:42 +0500 Subject: [PATCH] fix: eliminate TOCTOU race in file unlink calls --- src/specify_cli/extensions/__init__.py | 6 ++---- src/specify_cli/integrations/_helpers.py | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/specify_cli/extensions/__init__.py b/src/specify_cli/extensions/__init__.py index 6cd48582b0..6c60a5d557 100644 --- a/src/specify_cli/extensions/__init__.py +++ b/src/specify_cli/extensions/__init__.py @@ -3829,10 +3829,8 @@ def download_extension( 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 5c16935f1f..8ffc1b17a2 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) # ---------------------------------------------------------------------------