Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/borg/legacy/archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions src/borg/testsuite/legacy_archives_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",))
Expand Down
Loading