Skip to content

recreate: isolate tagged-dir exclusions per archive and place before include_patterns, fixes #10609 - #10611

Open
shikhabhadoria wants to merge 1 commit into
borgbackup:masterfrom
shikhabhadoria:fix-recreate-tagged-dirs-10609
Open

shikhabhadoria wants to merge 1 commit into
borgbackup:masterfrom
shikhabhadoria:fix-recreate-tagged-dirs-10609

Conversation

@shikhabhadoria

Copy link
Copy Markdown

Description

Fixes #10609.

RecreateMixIn.do_recreate() passes a single PatternMatcher instance to ArchiveRecreater, and ArchiveRecreater.matcher_add_tagged_dirs() previously mutated self.matcher in place by appending tag_files (IECommand.Include) and tagged_dirs (IECommand.ExcludeNoRecurse) at the end of self.matcher._items:

  1. When recreating multiple archives in one run, tagged_dirs added for an earlier archive remained in self.matcher._items for subsequent archives, deleting those paths from later archives even when the tag file was no longer present there (and making self.matcher.empty() false for all subsequent archives). ArchiveRecreater.recreate() now resets self.matcher._items from self.base_matcher_items at the start of each archive.
  2. When positional PATH arguments were given on the command line, build_matcher() placed matcher.include_patterns (IECommand.Include) in matcher._items before matcher_add_tagged_dirs() appended tagged_dirs (IECommand.ExcludeNoRecurse). Because PatternMatcher.match() is first-match-wins, the Include rule from args.paths matched first and tagged_dirs was never reached. matcher_add_tagged_dirs() now places tag_files (for tag items matching matcher) and tagged_dirs before matcher.include_patterns.

Tests (src/borg/testsuite/archiver/recreate_cmd_test.py):

  • test_recreate_exclude_caches_multiple_archives_and_paths: verifies that borg recreate --exclude-caches input excludes the tagged cache directory in arch1 while preserving the untagged directory of the same path in arch2.

Checklist

  • PR is against master (or maintenance branch if only applicable there)
  • New code has tests and docs where appropriate
  • Tests pass (run tox or the relevant test subset)
  • Commit messages are clean and reference related issues

…include_patterns, fixes borgbackup#10609

Reset self.matcher._items at the start of each ArchiveRecreater.recreate()
call so tagged-directory rules added by matcher_add_tagged_dirs() for one
archive do not leak into subsequent archives in the same run.

Also insert tag_files and tagged_dirs before matcher.include_patterns so
positional PATH arguments do not match before ExcludeNoRecurse rules.
@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.39%. Comparing base (94ac75b) to head (9ff62f3).
⚠️ Report is 7 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #10611   +/-   ##
=======================================
  Coverage   89.39%   89.39%           
=======================================
  Files         105      105           
  Lines       20340    20346    +6     
  Branches     3194     3195    +1     
=======================================
+ Hits        18182    18188    +6     
  Misses       1500     1500           
  Partials      658      658           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@shikhabhadoria

Copy link
Copy Markdown
Author

This PR is ready for review whenever convenient. All CI checks and tests are passing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

recreate: --exclude-caches and --exclude-if-present leak tagged-directory exclusions into subsequent archives and are bypassed by positional PATHs

1 participant