Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
whoschek committed Jul 30, 2024
1 parent 2790043 commit e9cd6ea
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions wbackup_zfs/wbackup_zfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ def incremental_replication_steps(self, src_snapshots: List[str], guids: List[st
steps.append(step)
i -= 1
else:
# it's a run of more than one dailies
# it's a run of more than one daily
i -= 1
# assert start != i
if start != i:
Expand Down Expand Up @@ -1305,22 +1305,20 @@ def filter_datasets(self, datasets: List[str], root_dataset: str) -> List[str]:

def filter_snapshots(self, snapshots: List[str]) -> List[str]:
"""Returns all snapshots that match at least one of the include regexes but none of the exclude regexes."""
include_snapshot_regexes = self.params.include_snapshot_regexes
exclude_snapshot_regexes = self.params.exclude_snapshot_regexes
results = []
for snapshot in snapshots:
if self.is_included_snapshot(snapshot):
i = snapshot.find('#') # bookmark separator
if i < 0:
i = snapshot.find('@') # snapshot separator
assert i >= 0
if self.is_included(snapshot[i+1:], include_snapshot_regexes, exclude_snapshot_regexes):
results.append(snapshot)
else:
self.debug("Excluding b/c snaphot regex:", snapshot)
return results

def is_included_snapshot(self, snapshot: str) -> bool:
params = self.params
p = snapshot.find('@') # snapshot separator
q = snapshot.find('#') # bookmark separator
i = min(p, q) + 1 if p >= 0 and q >= 0 else max(p, q) + 1
snapshot_tag = snapshot[i:] # substring after the first '@' or '#' char, whichever comes first
return self.is_included(snapshot_tag, params.include_snapshot_regexes, params.exclude_snapshot_regexes)

def is_included(self, name: str,
include_regexes: List[Tuple[re.Pattern, bool]],
exclude_regexes: List[Tuple[re.Pattern, bool]]) -> bool:
Expand Down

0 comments on commit e9cd6ea

Please sign in to comment.