platform: use FILE_FLAG_WRITE_THROUGH on Windows for SyncFile data durability, fixes #9388#9389
platform: use FILE_FLAG_WRITE_THROUGH on Windows for SyncFile data durability, fixes #9388#9389mr-raj12 wants to merge 1 commit intoborgbackup:masterfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9389 +/- ##
=======================================
Coverage 76.43% 76.43%
=======================================
Files 85 85
Lines 14800 14800
Branches 2212 2212
=======================================
Hits 11313 11313
Misses 2809 2809
Partials 678 678 ☔ View full report in Codecov by Sentry. |
ThomasWaldmann
left a comment
There was a problem hiding this comment.
some minor things i found
| oflags = os.O_WRONLY | (os.O_BINARY if binary else os.O_TEXT) | ||
| c_fd = msvcrt.open_osfhandle(handle, oflags) |
There was a problem hiding this comment.
are the flag values from os valid for that msvcrt call?
| """Integration: SyncFile creates file and writes data correctly.""" | ||
| from ...platform.windows import SyncFile | ||
|
|
||
| with tempfile.TemporaryDirectory() as tmpdir: |
There was a problem hiding this comment.
iirc there is a pytest fixture for temp dirs.
one is even using pathlib, so code can be prettier.
|
|
||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| path = os.path.join(tmpdir, "testfile") | ||
| open(path, "w").close() |
There was a problem hiding this comment.
pathlib Paths have .touch method.
|
Also: Please update your local master branch and then rebase this branch onto that master and force push. That should solve the CI test failures that are unrelated to your work. |
Description
Implement Windows-native
SyncFileusingCreateFileWwithFILE_FLAG_WRITE_THROUGHto bypass volatile write caches and write directly to persistent storage. This is the Windows equivalent of the macOSF_FULLFSYNCfix (#9383 / PR #9385).Fixes #9388
Changes
src/borg/platform/windows.pyx— addSyncFilesubclass usingCreateFileW+FILE_FLAG_WRITE_THROUGH; falls back to base when an existing fd is provided (e.g.SaveFile)src/borg/platform/__init__.py— importSyncFilefrom.windowsinstead of.basesrc/borg/platform/base.py— update resolved TODO commentsrc/borg/testsuite/platform/platform_test.py— addskipif_not_win32markersrc/borg/testsuite/platform/windows_test.py— 6 tests (write/read, FileExistsError, text mode, fd fallback, sync, write-through flag verification)Checklist
master(or maintenance branch if only applicable there)toxor the relevant test subset)