Skip to content

Commit 1219225

Browse files
fix: eliminate TOCTOU race in file unlink calls
1 parent 186ca25 commit 1219225

2 files changed

Lines changed: 3 additions & 6 deletions

File tree

‎src/specify_cli/extensions/__init__.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,10 +3829,8 @@ def download_extension(
38293829

38303830
def clear_cache(self):
38313831
"""Clear the catalog cache (both legacy and URL-hash-based files)."""
3832-
if self.cache_file.exists():
3833-
self.cache_file.unlink()
3834-
if self.cache_metadata_file.exists():
3835-
self.cache_metadata_file.unlink()
3832+
self.cache_file.unlink(missing_ok=True)
3833+
self.cache_metadata_file.unlink(missing_ok=True)
38363834
# Also clear any per-URL hash-based cache files
38373835
if self.cache_dir.exists():
38383836
for extra_cache in self.cache_dir.glob("catalog-*.json"):

‎src/specify_cli/integrations/_helpers.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ def _clear_init_options_for_integration(project_root: Path, integration_key: str
121121
def _remove_integration_json(project_root: Path) -> None:
122122
"""Remove ``.specify/integration.json`` if it exists."""
123123
path = project_root / INTEGRATION_JSON
124-
if path.exists():
125-
path.unlink()
124+
path.unlink(missing_ok=True)
126125

127126

128127
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)