Deleting a watch now removes the entire watch storage directory (#1408)

pull/1410/head
dgtlmoon 2 years ago committed by GitHub
parent 01af21f856
commit 7b8b50138b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -192,27 +192,24 @@ class ChangeDetectionStore:
tags.sort() tags.sort()
return tags return tags
def unlink_history_file(self, path):
try:
unlink(path)
except (FileNotFoundError, IOError):
pass
# Delete a single watch by UUID # Delete a single watch by UUID
def delete(self, uuid): def delete(self, uuid):
import pathlib
import shutil
with self.lock: with self.lock:
if uuid == 'all': if uuid == 'all':
self.__data['watching'] = {} self.__data['watching'] = {}
# GitHub #30 also delete history records # GitHub #30 also delete history records
for uuid in self.data['watching']: for uuid in self.data['watching']:
for path in self.data['watching'][uuid].history.values(): path = pathlib.Path(os.path.join(self.datastore_path, uuid))
self.unlink_history_file(path) shutil.rmtree(path)
self.needs_write_urgent = True
else: else:
for path in self.data['watching'][uuid].history.values(): path = pathlib.Path(os.path.join(self.datastore_path, uuid))
self.unlink_history_file(path) shutil.rmtree(path)
del self.data['watching'][uuid] del self.data['watching'][uuid]
self.needs_write_urgent = True self.needs_write_urgent = True

Loading…
Cancel
Save