test: cover atomic temp cleanup on interrupts
- add regression coverage for BaseException cleanup in atomic_json_write - add dedicated atomic_yaml_write tests, including interrupt cleanup - document why BaseException is intentional in both helpers
This commit is contained in:
4
utils.py
4
utils.py
@@ -50,6 +50,8 @@ def atomic_json_write(
|
||||
os.fsync(f.fileno())
|
||||
os.replace(tmp_path, path)
|
||||
except BaseException:
|
||||
# Intentionally catch BaseException so temp-file cleanup still runs for
|
||||
# KeyboardInterrupt/SystemExit before re-raising the original signal.
|
||||
try:
|
||||
os.unlink(tmp_path)
|
||||
except OSError:
|
||||
@@ -96,6 +98,8 @@ def atomic_yaml_write(
|
||||
os.fsync(f.fileno())
|
||||
os.replace(tmp_path, path)
|
||||
except BaseException:
|
||||
# Match atomic_json_write: cleanup must also happen for process-level
|
||||
# interruptions before we re-raise them.
|
||||
try:
|
||||
os.unlink(tmp_path)
|
||||
except OSError:
|
||||
|
||||
Reference in New Issue
Block a user