From 06fd43ee245c2b42d1788317f7acff0aaadb560a Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Mon, 16 Feb 2026 17:59:40 +0100 Subject: [PATCH] safer cleanup --- changedetectionio/tests/util.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/changedetectionio/tests/util.py b/changedetectionio/tests/util.py index 0f2bcce7a..6c30aeba1 100644 --- a/changedetectionio/tests/util.py +++ b/changedetectionio/tests/util.py @@ -183,8 +183,19 @@ def delete_all_watches(client=None): # Delete any old watch metadata from pathlib import Path - for file in Path(client.application.config.get('DATASTORE').datastore_path).rglob("*.json"): - file.unlink() + + base_path = Path( + client.application.config.get('DATASTORE').datastore_path + ).resolve() + + max_depth = 2 + + for file in base_path.rglob("*.json"): + # Calculate depth relative to base path + depth = len(file.relative_to(base_path).parts) - 1 + + if depth <= max_depth and file.is_file(): + file.unlink() def wait_for_all_checks(client=None):