Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion hermes_cli/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,21 @@ def restore_cron_jobs_if_emptied(

try:
live_path.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(snap_path, live_path)
fd, tmp_path = tempfile.mkstemp(
dir=str(live_path.parent), suffix=".tmp", prefix=".cron_restore_"
)
try:
with os.fdopen(fd, "wb") as f:
f.write(snap_path.read_bytes())
f.flush()
os.fsync(f.fileno())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use utils.atomic_replace(tmp_path, live_path) here. Direct os.replace replaces a jobs.json symlink itself; atomic_replace preserves the managed link while updating its referent (utils.py:91-136), and cron/jobs.py already uses it for normal job-store saves.

os.replace(tmp_path, live_path)
except BaseException:
try:
os.unlink(tmp_path)
except OSError:
pass
raise
except (OSError, PermissionError) as exc:
logger.error(
"Cron jobs were emptied during update but auto-restore failed: %s", exc
Expand Down
Loading