-
-
Notifications
You must be signed in to change notification settings - Fork 827
Description
On Windows, SyncFile currently uses the generic base implementation (src/borg/platform/base.py), which relies on os.fsync(). This does not guarantee data durability on Windows — os.fsync() maps to FlushFileBuffers(), which only flushes the OS cache to the drive's write cache, not necessarily to persistent storage.
The base class already has a TODO (line 154):
A Windows implementation should use CreateFile with FILE_FLAG_WRITE_THROUGH.
Current state
| Platform | SyncFile | Data durability mechanism |
|---|---|---|
| Linux | Custom (linux.pyx) |
sync_file_range + fdatasync |
| macOS | Base + custom fdatasync (darwin.pyx) |
F_FULLFSYNC (PR #9385) |
| Windows | Base fallback | os.fsync() → FlushFileBuffers() — no write-through guarantee |
Proposed solution
Implement a Windows-native SyncFile in src/borg/platform/windows.pyx that:
- Opens the file using
win32file.CreateFile(orctypes/msvcrt) withFILE_FLAG_WRITE_THROUGHto bypass the drive write cache - Overrides
sync()to useFlushFileBuffers()(already whatos.fsync()does, but combined with write-through flag it provides stronger guarantees) - Optionally implements
fdatasync()andsync_dir()for Windows in the platform module
Why this matters
Without FILE_FLAG_WRITE_THROUGH, writes on Windows may sit in the drive's volatile write cache. A power failure or crash can lose data that borg considers durably written, potentially corrupting the repository.
This is the Windows equivalent of the macOS F_FULLFSYNC fix (#9383 / PR #9385).
References
- TODO in
src/borg/platform/base.py:154 - macOS F_FULLFSYNC: platform: use F_FULLSYNC on macOS for SyncFile data durability #9383 / PR platform: use F_FULLSYNC on macOS for SyncFile data durability, fixes #9383 #9385
- Linux
sync_file_range:src/borg/platform/linux.pyx - Windows
FILE_FLAG_WRITE_THROUGH: Microsoft docs