Skip to content

platform: use F_FULLSYNC on macOS for SyncFile data durability #9383

@mr-raj12

Description

@mr-raj12

Summary

  • SyncFile.sync() calls platform.fdatasync(self.fd), which resolves to os.fdatasync or os.fsync
  • On macOS, fsync() only flushes data to the drive's write cache, not to persistent storage
  • True durability on macOS requires fcntl(fd, F_FULLSYNC)
  • This was already acknowledged with a TODO comment at src/borg/platform/base.py:154: TODO: Use F_FULLSYNC on macOS.
  • Without F_FULLSYNC, Borg's data durability guarantees on macOS are weaker than intended - a power loss could result in data that SyncFile believed was safely persisted being lost

Proposed fix

Detect macOS (sys.platform == "darwin") and use fcntl.fcntl(fd, fcntl.F_FULLSYNC) in the fdatasync path:

import sys

if sys.platform == "darwin":
    import fcntl
    fcntl.fcntl(fd, fcntl.F_FULLSYNC)
else:
    os.fsync(fd)

This could either live in platform/darwin.py as a platform-specific override of fdatasync, or inline in base.py with a platform check.

File Change
src/borg/platform/base.py or src/borg/platform/darwin.py Use fcntl.F_FULLSYNC on macOS instead of os.fsync;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions