Fix F_FULLFSYNC on PyPy + Fallback if unsupported

This commit is contained in:
Unrud 2022-02-03 14:36:53 +01:00
parent 7e29d9b5c3
commit 4d4c3bda75

View File

@ -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: