From 45e3f6b1a2280d9d3fc51e7ba92aaf653d321305 Mon Sep 17 00:00:00 2001 From: manor-tile <159947643+manor-tile@users.noreply.github.com> Date: Mon, 18 Mar 2024 17:05:16 +0100 Subject: [PATCH] error if X in last-X is too big --- src/log.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/log.py b/src/log.py index eb513e545..6b40ac17f 100755 --- a/src/log.py +++ b/src/log.py @@ -173,15 +173,19 @@ def log_show( share """ - match_path = re.match(r"last(?:-(?P[0-9]{1,6}))?$", path) + # Set up path with correct value if 'last' or 'last-X' magic keywords are used + last = re.match(r"last(?:-(?P[0-9]{1,6}))?$", path) + if last: + position = 1 + if last.group("position") is not None: + position += int(last.group("position")) - if match_path: - if match_path.group("position") == None: - position = 1 - else: - position = int(match_path.group("position")) + 1 - logs = log_list() - path = list(logs["operation"])[-position]["path"] + logs = list(log_list()["operation"]) + + if position > len(logs): + raise YunohostValidationError(f"There isn't that many logs", raw_msg=True) + + path = logs[-position]["path"] if share: filter_irrelevant = True