fix(cron): tolerate unsupported directory fsync

This commit is contained in:
chengyongru
2026-07-01 19:51:43 +08:00
committed by Xubin Ren
parent 2ec4044217
commit f6d1dba32a
2 changed files with 36 additions and 2 deletions
+7 -2
View File
@@ -1,6 +1,7 @@
"""Cron service for scheduling agent tasks."""
import asyncio
import errno
import json
import os
import time
@@ -456,11 +457,15 @@ class CronService:
os.replace(tmp_path, path)
# fsync the parent directory so the rename itself is durable.
# Skip on Windows where opening a directory raises PermissionError;
# NTFS journals metadata synchronously so this is a no-op there.
# some shared filesystems reject directory fsync with EINVAL.
with suppress(PermissionError):
fd = os.open(str(path.parent), os.O_RDONLY)
try:
os.fsync(fd)
try:
os.fsync(fd)
except OSError as exc:
if exc.errno != errno.EINVAL:
raise
finally:
os.close(fd)
except BaseException: