Skip to content

patterns: clean up TODOs, move is_include_cmd to IECommand property, fixes #9442#9542

Open
mr-raj12 wants to merge 2 commits intoborgbackup:masterfrom
mr-raj12:cleanup-patterns-todos-master
Open

patterns: clean up TODOs, move is_include_cmd to IECommand property, fixes #9442#9542
mr-raj12 wants to merge 2 commits intoborgbackup:masterfrom
mr-raj12:cleanup-patterns-todos-master

Conversation

@mr-raj12
Copy link
Contributor

Description

Address the TODO items in src/borg/patterns.py as discussed in #9442:

  1. recurse_dir_default: Replaced the misleading TODO with a comment explaining why it must stay True as include patterns inside excluded directories (+ inside -) depend on it.

  2. is_include_cmd: Moved from a dict on PatternMatcher to an is_include property on IECommand and now the matcher calls cmd.is_include instead of doing a dict lookup.

  3. RootPath validation: Added a warning when the root path doesn't start with /, so backups don't fail due to a typo.

  4. command_recurses_dir: Replaced cmd not in [IECommand.ExcludeNoRecurse] with explicit if/raise branches using is comparisons. Now raises ValueError for unexpected commands like RootPath or PatternStyle.

Tests updated to use real IECommand values and cover the new code paths.

Checklist

  • PR is against master
  • New code has tests and docs where appropriate
  • Tests pass
  • Commit messages are clean and reference related issues

@codecov
Copy link

codecov bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.38%. Comparing base (9d5687d) to head (13c7df2).
⚠️ Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
src/borg/patterns.py 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9542      +/-   ##
==========================================
- Coverage   83.39%   83.38%   -0.02%     
==========================================
  Files          87       87              
  Lines       15469    15484      +15     
  Branches     2321     2325       +4     
==========================================
+ Hits        12901    12911      +10     
- Misses       1818     1820       +2     
- Partials      750      753       +3     

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


if cmd is IECommand.RootPath:
# TODO: validate string?
if not remainder_str.startswith("/"):
Copy link
Member

@ThomasWaldmann ThomasWaldmann Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the roots in a pattern file are somehow equivalent to the PATHs given as cli arguments for borg create.

we do not require the PATHs to be absolute paths, so guess we should not require the roots to be abs paths either.

in both cases it might be clearer and less risky to use abs paths, but the user can use rel paths on their own risk.

validation: check if the path exists and if not, output a warning.

@mr-raj12 mr-raj12 force-pushed the cleanup-patterns-todos-master branch from 6d42b24 to 13c7df2 Compare March 25, 2026 19:41
if not remainder_str.startswith("/"):
logger.warning("Root path %r does not look like an absolute path", remainder_str)
# Check if path is absolute
is_absolute = remainder_str.startswith("/")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that does not work on win32.

Path(p).is_absolute() or so.


# Warn about relative paths
if not is_absolute:
logger.warning("Root path %r is relative, recommended to use absolute path", remainder_str)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..., it is recommended to use an ...

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.

2 participants