From 6f04b356c9b95ba77b2e993e776393352997181d Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Thu, 16 Oct 2025 15:00:55 +0200 Subject: [PATCH] Improved delete --- changedetectionio/store.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/changedetectionio/store.py b/changedetectionio/store.py index 7e4a20bc1..893cdac34 100644 --- a/changedetectionio/store.py +++ b/changedetectionio/store.py @@ -228,26 +228,36 @@ class ChangeDetectionStore: d['settings']['application']['active_base_url'] = active_base_url.strip('" ') return d + from pathlib import Path + + def delete_path(self, path: Path): + import shutil + """Delete a file or directory tree, including the path itself.""" + if not path.exists(): + return + if path.is_file() or path.is_symlink(): + path.unlink(missing_ok=True) # deletes a file or symlink + else: + shutil.rmtree(path, ignore_errors=True) # deletes dir *and* its contents + # Delete a single watch by UUID def delete(self, uuid): import pathlib - import shutil with self.lock: if uuid == 'all': self.__data['watching'] = {} time.sleep(1) # Mainly used for testing to allow all items to flush before running next test - - # GitHub #30 also delete history records for uuid in self.data['watching']: path = pathlib.Path(os.path.join(self.datastore_path, uuid)) if os.path.exists(path): - shutil.rmtree(path) + self.delete(uuid) else: path = pathlib.Path(os.path.join(self.datastore_path, uuid)) if os.path.exists(path): - shutil.rmtree(path) + self.delete_path(path) + del self.data['watching'][uuid] self.needs_write_urgent = True