extract: refuse to extract into a non-empty directory, fixes #10057 - #10390
Merged
ThomasWaldmann merged 1 commit intoSep 19, 2026
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #10390 +/- ##
==========================================
- Coverage 88.19% 88.16% -0.03%
==========================================
Files 103 103
Lines 18822 18840 +18
Branches 2919 2924 +5
==========================================
+ Hits 16600 16611 +11
- Misses 1548 1553 +5
- Partials 674 676 +2 ☔ View full report in Codecov by Harness. |
ThomasWaldmann
force-pushed
the
extract-nonempty-10057
branch
from
September 19, 2026 01:33
9e31e72 to
9df03b3
Compare
…up#10057 Extracting into a non-empty directory replaces existing files that are in the way and leaves all other existing files as they are, so the result is a mix of existing and extracted files. Accidentally running "borg extract" in a directory that is in use (like a home directory) thus replaced current files by their archived state and blended the archive into the directory. Now borg aborts with Archive.ExtractionDirNotEmpty (rc 33) before writing anything if the current directory is not empty, unless --continue is given. This also applies when only a part of the archive is extracted. --dry-run and --stdout do not write into the directory, so they are not checked. No new option: --continue already is the way to extract into a directory that has contents. Its help and the extract docs now describe what it does (skip files that are fully extracted already, replace other existing files) and that a damaged file with unchanged size and mtime must be removed before it can be extracted again. Tests that extracted repeatedly into the same directory now use --continue or a fresh directory. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
ThomasWaldmann
force-pushed
the
extract-nonempty-10057
branch
from
September 19, 2026 12:30
9df03b3 to
1b7ff2b
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.
Fixes #10057.
Problem
Extracting into a non-empty directory
Running
borg extractby accident in a directory that is in use (the issue's example: the home directory, with an archive made byborg create ... .) thus replaces current files by their archived state and blends the archive into the directory. The docs already said that only extracting into an empty directory is supported, but nothing enforced it.Change
borg extractaborts with the newArchive.ExtractionDirNotEmpty(rc 33) before writing anything if the current directory is not empty, unless--continueis given:same rule when only a part of the archive is extracted (
PATHarguments / patterns): replacing one file in place is as destructive as replacing many.--dry-runand--stdoutdo not write into the directory, so they are not checked.the check is strict (any directory entry counts, no special cases like
lost+foundor.DS_Store). It costs oneos.listdircall.no new option, no prompt:
--continuealready is the way to extract into a directory that has contents. It is not a forced overwrite though - files with the same type/mode, size and mtime are skipped - so the docs now say that a file that was damaged without a change of size and mtime (bit rot) has to be removed before it can be extracted again.This is a behaviour change for scripts and frontends that extract into a non-empty directory: they need to add
--continue(or use an empty directory). It needs a compatibility note in the change log (not part of this PR).The
--overwrite=MODEfamily suggested in the issue is not needed for this and can still be added later (--continuewould then bechanged).Docs
--continuehelp: describe the refusal, the mix of existing and extracted files, and what--continuereally does.--continue, which the second and later partial extracts into one directory now need), usage examples.docs/internals/frontends.rst: new error in the error list (as generated byscripts/errorlist.py).Tests
test_extract_non_empty_dir: refusal for full and partial extraction (nothing extracted, existing file untouched),--dry-run/--stdoutstill work,--continueextracts and replaces.--continue, except:test_verify_data_wrong_chunk_content: the second extraction must really read the file again,--continuewould skip it, so it extracts into a fresh directory.test_recreate_subtree_hardlinks: extracts the second archive into a fresh directory (with--continueit would depend on the hard link fix in extract --continue: keep groups of hard links together #10387).Related: #10387 fixes
--continuebreaking up groups of hard links, which matters more now that--continueis the way to extract into a non-empty directory. The two PRs are independent of each other.🤖 Generated with Claude Code