repository: do not crash on missing segment files/dirs, fixes #3225 - #10112
Draft
ThomasWaldmann wants to merge 1 commit into
Draft
repository: do not crash on missing segment files/dirs, fixes #3225#10112ThomasWaldmann wants to merge 1 commit into
ThomasWaldmann wants to merge 1 commit into
Conversation
…kup#3225 get_write_fd only created the segment dir for the first segment of a dir, so writing a segment file into a dir that is missing (e.g. removed by a fsck) crashed with FileNotFoundError. This also happened to 'borg check --repair' when it wanted to add a commit tag to segment <index transaction id> + 1, so repair died on the damage it is supposed to repair. get_fd let a FileNotFoundError escape when a segment file the repository index still refers to was gone, giving a traceback instead of telling what is wrong. It now raises an IntegrityError naming the missing segment file and pointing at borg check --repair. As the archives check catches IntegrityError, 'borg check --verify-data' now reports (and with --repair deletes) the affected chunks instead of crashing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ThomasWaldmann
marked this pull request as draft
August 14, 2026 19:47
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 1.4-maint #10112 +/- ##
=============================================
- Coverage 82.62% 82.12% -0.51%
=============================================
Files 38 38
Lines 11432 11435 +3
Branches 1803 1802 -1
=============================================
- Hits 9446 9391 -55
- Misses 1408 1460 +52
- Partials 578 584 +6 ☔ View full report in Codecov by Harness. |
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.
Two crashes on repositories that lost segment files or segment dirs (e.g. removed by a filesystem check), both reported in #3225.
Writing into a missing segment dir
LoggedIO.get_write_fdonly created the segment dir if the segment was the first one of that dir (segment % segments_per_dir == 0), so writing a segment file into a dir that is not there any more crashed withFileNotFoundError.borg check --repairruns into this when it adds a commit tag to segment<index transaction id> + 1and that segment's dir is gone - so repair died on the damage it is meant to repair. The dir is now created whenever it is missing.Reading a missing segment file
LoggedIO.get_fdlet aFileNotFoundErrorescape when the repository index still referred to a segment file that is gone, soborg extract/borg mount/ the archives check just dumped a traceback. It now raises anIntegrityErrorthat names the missing segment file and points atborg check --repair:The archives check catches
IntegrityErroraroundRepository.get, soborg check --verify-datanow logs the affected chunks and continues (and deletes them with--repair, so the files can be repaired and later healed) instead of aborting.Both tests fail with
FileNotFoundErrorwithout the fix.