From 43d56165f55b827b7a9c82f8170b679452fa0875 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 29 Jul 2026 22:42:04 +0200 Subject: [PATCH] legacy: support date: archive patterns for --from-borg1 The date: archive matching pattern (#8776) was implemented for borg2 repos in manifest.py but not in the legacy code path used by borg2 repo-list/transfer --from-borg1, so date: patterns matched no archives when filtering legacy (borg 1.x) repos. Add the same date: branch to LegacyArchives._matching_info_tuples, mirroring the borg2 implementation. Fixes #9949 Co-Authored-By: Claude Opus 4.8 --- src/borg/legacy/archives.py | 9 ++++++++- src/borg/testsuite/legacy_archives_test.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/borg/legacy/archives.py b/src/borg/legacy/archives.py index 6f6f403dea..5f216b333e 100644 --- a/src/borg/legacy/archives.py +++ b/src/borg/legacy/archives.py @@ -15,7 +15,7 @@ from ..helpers.datastruct import StableDict from ..helpers.errors import CommandError, Error from ..helpers.parseformat import bin_to_hex -from ..helpers.time import parse_timestamp +from ..helpers.time import parse_timestamp, compile_date_pattern, DatePatternError from ..item import ArchiveItem from ..patterns import get_regex_from_pattern @@ -123,6 +123,13 @@ def _matching_info_tuples(self, match_patterns, match_end, *, deleted=False): elif match.startswith("host:"): wanted_host = match.removeprefix("host:") archive_infos = [x for x in archive_infos if x.host == wanted_host] + elif match.startswith("date:"): + wanted_date = match.removeprefix("date:") + try: + date_matches = compile_date_pattern(wanted_date) + except DatePatternError as exc: + raise CommandError(f"Invalid date pattern: {match} ({exc})") + archive_infos = [x for x in archive_infos if date_matches(x.ts)] else: match = match.removeprefix("name:") regex = get_regex_from_pattern(match) diff --git a/src/borg/testsuite/legacy_archives_test.py b/src/borg/testsuite/legacy_archives_test.py index 55e4180958..916b709f2d 100644 --- a/src/borg/testsuite/legacy_archives_test.py +++ b/src/borg/testsuite/legacy_archives_test.py @@ -371,6 +371,20 @@ def test_list_match_host(): assert la.list(match=["host:laptop"]) == [i1] +def test_list_match_date(): + i1 = _archiveinfo("a", _id(1), ts=TS) # 2020-06-01 + i2 = _archiveinfo("b", _id(2), ts=TS2) # 2021-06-01 + la = _make_list_target([i1, i2]) + assert la.list(match=["date:2020-06"]) == [i1] + + +def test_list_match_date_invalid_raises(): + i1 = _archiveinfo("a", _id(1)) + la = _make_list_target([i1]) + with pytest.raises(CommandError, match="Invalid date pattern"): + la.list(match=["date:not-a-date"]) + + def test_list_match_tags(): i1 = _archiveinfo("a", _id(1), tags=("prod", "db")) i2 = _archiveinfo("b", _id(2), tags=("dev",))