cache: add seek()/tell() to SyncFile, use SaveFile in _write_files_cache, fixes #9390#9392
Open
mr-raj12 wants to merge 1 commit intoborgbackup:masterfrom
Open
cache: add seek()/tell() to SyncFile, use SaveFile in _write_files_cache, fixes #9390#9392mr-raj12 wants to merge 1 commit intoborgbackup:masterfrom
mr-raj12 wants to merge 1 commit intoborgbackup:masterfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9392 +/- ##
==========================================
+ Coverage 76.43% 76.46% +0.02%
==========================================
Files 85 85
Lines 14800 14810 +10
Branches 2212 2213 +1
==========================================
+ Hits 11313 11324 +11
Misses 2809 2809
+ Partials 678 677 -1 ☔ View full report in Codecov by Sentry. |
ThomasWaldmann
requested changes
Feb 22, 2026
Member
ThomasWaldmann
left a comment
There was a problem hiding this comment.
good change, found some minor things.
6c1017b to
c095cc8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
_write_files_cache()incache.pyhas a TODO noting thatSaveFilecouldn't be used becauseSyncFilelacks.seek()and.tell()SaveFile, the files cache is written directly to the final path — a crash mid-write can leave a corrupted fileSaveFileprovides atomic writes (temp file +os.replace), but its__enter__returns aSyncFile, andIntegrityCheckedFileneeds.seek()/.tell()on its backing fd for hash finalization (hash_lengthcallsseek(0, SEEK_END)+tell())SyncFile, makeclose()idempotent (needed because theIntegrityCheckedFile→ hasher →FileLikeWrapperexit chain closes theSyncFilebeforeSaveFile.__exit__tries to close it again), then refactor_write_files_cacheto useSaveFileFixes #9390
Changes
src/borg/platform/base.pyseek()andtell()toSyncFile, delegating toself.f; makeclose()idempotent withif self.f.closed: returnguardsrc/borg/cache.py_write_files_cacheto wrap writes inSaveFile+IntegrityCheckedFile(override_fd=...)for atomic updates; remove TODO commentsrc/borg/testsuite/platform/all_test.pyseek/tell, idempotentclose, andSaveFile+IntegrityCheckedFileintegrationsrc/borg/testsuite/crypto/file_integrity_test.pyIntegrityCheckedFilewithSyncFileasoverride_fdChecklist
master