From 7b8b50138bd27411f6fb366aa733a74933bf1400 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Sat, 11 Feb 2023 14:10:54 +0100 Subject: [PATCH] Deleting a watch now removes the entire watch storage directory (#1408) --- changedetectionio/store.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/changedetectionio/store.py b/changedetectionio/store.py index 84e97395..ad16de93 100644 --- a/changedetectionio/store.py +++ b/changedetectionio/store.py @@ -192,27 +192,24 @@ class ChangeDetectionStore: tags.sort() return tags - def unlink_history_file(self, path): - try: - unlink(path) - except (FileNotFoundError, IOError): - pass - # Delete a single watch by UUID def delete(self, uuid): + import pathlib + import shutil + with self.lock: if uuid == 'all': self.__data['watching'] = {} # GitHub #30 also delete history records for uuid in self.data['watching']: - for path in self.data['watching'][uuid].history.values(): - self.unlink_history_file(path) + path = pathlib.Path(os.path.join(self.datastore_path, uuid)) + shutil.rmtree(path) + self.needs_write_urgent = True else: - for path in self.data['watching'][uuid].history.values(): - self.unlink_history_file(path) - + path = pathlib.Path(os.path.join(self.datastore_path, uuid)) + shutil.rmtree(path) del self.data['watching'][uuid] self.needs_write_urgent = True