From 14e2a6b89d762f38c33726304c84896aa1661e38 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Wed, 2 Aug 2023 10:23:22 -0700 Subject: [PATCH] Omit "--glob-archives" or "--match-archives" Borg flag when its value would be "*" (#734). --- NEWS | 2 ++ borgmatic/borg/flags.py | 3 +++ tests/unit/borg/test_flags.py | 26 +++++++++++++++++++------- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 88b9cc9..0c5d84a 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,8 @@ * #732: Include multiple configuration files with a single "!include". See the documentation for more information: https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/#multiple-merge-includes + * #734: Omit "--glob-archives" or "--match-archives" Borg flag when its value would be "*" (meaning + all archives). 1.8.0 * #575: BREAKING: For the "borgmatic borg" action, instead of implicitly injecting diff --git a/borgmatic/borg/flags.py b/borgmatic/borg/flags.py index 986531b..dc7e84d 100644 --- a/borgmatic/borg/flags.py +++ b/borgmatic/borg/flags.py @@ -77,6 +77,9 @@ def make_match_archives_flags(match_archives, archive_name_format, local_borg_ve derived_match_archives = re.sub(r'\{(now|utcnow|pid)([:%\w\.-]*)\}', '*', archive_name_format) + if derived_match_archives == '*': + return () + if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version): return ('--match-archives', f'sh:{derived_match_archives}') else: diff --git a/tests/unit/borg/test_flags.py b/tests/unit/borg/test_flags.py index 2eaff0a..804dd8f 100644 --- a/tests/unit/borg/test_flags.py +++ b/tests/unit/borg/test_flags.py @@ -86,28 +86,28 @@ def test_make_repository_archive_flags_with_borg_features_joins_repository_and_a @pytest.mark.parametrize( - 'match_archives, archive_name_format,feature_available,expected_result', + 'match_archives,archive_name_format,feature_available,expected_result', ( (None, None, True, ()), (None, '', True, ()), ( 're:foo-.*', - '{hostname}-{now}', + '{hostname}-{now}', # noqa: FS003 True, ('--match-archives', 're:foo-.*'), - ), # noqa: FS003 + ), ( 'sh:foo-*', - '{hostname}-{now}', + '{hostname}-{now}', # noqa: FS003 False, ('--glob-archives', 'foo-*'), - ), # noqa: FS003 + ), ( 'foo-*', - '{hostname}-{now}', + '{hostname}-{now}', # noqa: FS003 False, ('--glob-archives', 'foo-*'), - ), # noqa: FS003 + ), ( None, '{hostname}-docs-{now}', # noqa: FS003 @@ -133,6 +133,18 @@ def test_make_repository_archive_flags_with_borg_features_joins_repository_and_a False, ('--glob-archives', '{hostname}-docs-*'), # noqa: FS003 ), + ( + None, + '{now}', # noqa: FS003 + False, + (), + ), + ( + None, + '{now}', # noqa: FS003 + True, + (), + ), (None, '{utcnow}-docs-{user}', False, ('--glob-archives', '*-docs-{user}')), # noqa: FS003 ), )