diff --git a/src/specify_cli/_utils.py b/src/specify_cli/_utils.py index 85b659d67b..1c767cab5b 100644 --- a/src/specify_cli/_utils.py +++ b/src/specify_cli/_utils.py @@ -192,8 +192,11 @@ def atomic_write_json(target_file: Path, payload: dict[str, Any]) -> None: os.replace(temp_path, target_file) except Exception: - if temp_path and temp_path.exists(): - temp_path.unlink() + if temp_path: + try: + temp_path.unlink(missing_ok=True) + except OSError: + pass raise try: diff --git a/src/specify_cli/integrations/manifest.py b/src/specify_cli/integrations/manifest.py index ef2a9fc893..ffd6251d0b 100644 --- a/src/specify_cli/integrations/manifest.py +++ b/src/specify_cli/integrations/manifest.py @@ -451,8 +451,10 @@ def save(self) -> Path: _ensure_safe_manifest_destination(self.project_root, path) os.replace(temp_path, path) finally: - if temp_path.exists(): - temp_path.unlink() + try: + temp_path.unlink(missing_ok=True) + except OSError: + pass return path @classmethod diff --git a/src/specify_cli/shared_infra.py b/src/specify_cli/shared_infra.py index 1c8d727d73..5585e1f86c 100644 --- a/src/specify_cli/shared_infra.py +++ b/src/specify_cli/shared_infra.py @@ -262,8 +262,10 @@ def _write_shared_bytes( _ensure_safe_shared_destination(project_path, dest) os.replace(temp_path, dest) finally: - if temp_path.exists(): - temp_path.unlink() + try: + temp_path.unlink(missing_ok=True) + except OSError: + pass _BASH_FORMAT_COMMAND_RE = re.compile(