Skip to content

Comments

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

Merged
ThomasWaldmann merged 1 commit intoborgbackup:masterfrom
mr-raj12:darwin-f-fullsync
Feb 20, 2026
Merged

platform: use F_FULLSYNC on macOS for SyncFile data durability, fixes #9383#9385
ThomasWaldmann merged 1 commit intoborgbackup:masterfrom
mr-raj12:darwin-f-fullsync

Conversation

@mr-raj12
Copy link
Contributor

  • 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 requires fcntl(fd, F_FULLFSYNC) — without it, a power loss could lose data that SyncFile believed was safely persisted
    • This was acknowledged with a TODO at src/borg/platform/base.py:154: TODO: Use F_FULLSYNC on macOS.
    • Implements a platform-specific sync wrapper as suggested in platform: use F_FULLSYNC on macOS for SyncFile data durability #9383

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

    Changes

    File Change
    src/borg/platform/darwin.pyx Add fdatasync() using fcntl F_FULLFSYNC with os.fsync() fallback; add sync_dir() using the same
    src/borg/platform/__init__.py Import fdatasync, sync_dir from .darwin in the darwin block
    src/borg/platform/base.py Remove resolved TODO comment
    src/borg/testsuite/platform/darwin_test.py Add 4 tests: F_FULLFSYNC usage, fsync fallback, fdatasync integration, sync_dir integration

    Checklist

    • PR is against master
    • New code has tests
    • Tests pass
    • Commit message references related issue
    • Code formatted with black

@codecov
Copy link

codecov bot commented Feb 20, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 76.43%. Comparing base (cace06f) to head (0354697).
⚠️ Report is 3 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/borg/platform/__init__.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9385      +/-   ##
==========================================
- Coverage   76.44%   76.43%   -0.01%     
==========================================
  Files          85       85              
  Lines       14799    14800       +1     
  Branches     2212     2212              
==========================================
  Hits        11313    11313              
- Misses       2808     2809       +1     
  Partials      678      678              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ThomasWaldmann
Copy link
Member

For performance reasons, we don't do macOS tests for PRs, so we have to check this when it is merged.

Also a backport to 1.4-maint is likely needed.

@mr-raj12
Copy link
Contributor Author

For performance reasons, we don't do macOS tests for PRs, so we have to check this when it is merged.

Also a backport to 1.4-maint is likely needed.

sure and shall I prepare the backport PR for 1.4-maint now or after this is merged to master?

@ThomasWaldmann ThomasWaldmann merged commit 9f89e16 into borgbackup:master Feb 20, 2026
17 of 19 checks passed
@github-actions
Copy link

Backport failed for 1.4-maint, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 1.4-maint
git worktree add -d .worktree/backport-9385-to-1.4-maint origin/1.4-maint
cd .worktree/backport-9385-to-1.4-maint
git switch --create backport-9385-to-1.4-maint
git cherry-pick -x 0354697c56e4ea047b4ca6550622fab5e5e505f4

@ThomasWaldmann
Copy link
Member

Wait until the macOS tests there are finished and successful:

https://github.com/borgbackup/borg/actions/runs/22236158222

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

platform: use F_FULLSYNC on macOS for SyncFile data durability

2 participants