Skip to content

Commit c0d362c

Browse files
fix: catch OSError during temp file cleanup to avoid masking errors
Wrap unlink(missing_ok=True) in try/except OSError in finally/except blocks to prevent cleanup failures from masking the original exception.
1 parent a4bd37d commit c0d362c

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

‎src/specify_cli/_utils.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ def atomic_write_json(target_file: Path, payload: dict[str, Any]) -> None:
193193
os.replace(temp_path, target_file)
194194
except Exception:
195195
if temp_path:
196-
temp_path.unlink(missing_ok=True)
196+
try:
197+
temp_path.unlink(missing_ok=True)
198+
except OSError:
199+
pass
197200
raise
198201

199202
try:

‎src/specify_cli/integrations/manifest.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,10 @@ def save(self) -> Path:
451451
_ensure_safe_manifest_destination(self.project_root, path)
452452
os.replace(temp_path, path)
453453
finally:
454-
temp_path.unlink(missing_ok=True)
454+
try:
455+
temp_path.unlink(missing_ok=True)
456+
except OSError:
457+
pass
455458
return path
456459

457460
@classmethod

‎src/specify_cli/shared_infra.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,10 @@ def _write_shared_bytes(
262262
_ensure_safe_shared_destination(project_path, dest)
263263
os.replace(temp_path, dest)
264264
finally:
265-
temp_path.unlink(missing_ok=True)
265+
try:
266+
temp_path.unlink(missing_ok=True)
267+
except OSError:
268+
pass
266269

267270

268271
_BASH_FORMAT_COMMAND_RE = re.compile(

0 commit comments

Comments
 (0)