From 4d4c3bda75ad9d9a2b373bcd5a998a523d33679e Mon Sep 17 00:00:00 2001 From: Unrud Date: Thu, 3 Feb 2022 14:36:53 +0100 Subject: [PATCH] Fix F_FULLFSYNC on PyPy + Fallback if unsupported --- radicale/pathutils.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/radicale/pathutils.py b/radicale/pathutils.py index 56e6fa0..ff4565e 100644 --- a/radicale/pathutils.py +++ b/radicale/pathutils.py @@ -88,6 +88,10 @@ if sys.platform == "linux": ctypes.c_uint] renameat2.restype = ctypes.c_int +if sys.platform == "darwin": + # Definition missing in PyPy + F_FULLFSYNC: int = getattr(fcntl, "F_FULLFSYNC", 51) + class RwLock: """A readers-Writer lock that locks a file.""" @@ -193,10 +197,15 @@ def rename_exchange(src: str, dst: str) -> None: def fsync(fd: int) -> None: - if sys.platform != "win32" and hasattr(fcntl, "F_FULLFSYNC"): - fcntl.fcntl(fd, fcntl.F_FULLFSYNC) - else: - os.fsync(fd) + if sys.platform == "darwin": + try: + fcntl.fcntl(fd, F_FULLFSYNC) + return + except OSError as e: + # Fallback if F_FULLFSYNC not supported by filesystem + if e.errno != errno.EINVAL: + raise + os.fsync(fd) def strip_path(path: str) -> str: