From 2dcfc22d0fc6b27eea4ae7a03019a94a902a3f9e Mon Sep 17 00:00:00 2001 From: Quratulain-bilal Date: Tue, 28 Jul 2026 22:56:25 +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 2874012fb7..877cce9e10 100644 --- a/src/specify_cli/extensions/__init__.py +++ b/src/specify_cli/extensions/__init__.py @@ -3758,10 +3758,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 b95830b075..45545380ad 100644 --- a/src/specify_cli/integrations/_helpers.py +++ b/src/specify_cli/integrations/_helpers.py @@ -120,8 +120,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) # ---------------------------------------------------------------------------