Adding helper method to remove text files that are not in the index

This commit is contained in:
dgtlmoon
2021-06-16 10:57:55 +10:00
parent 878584f043
commit d304449cb1
2 changed files with 26 additions and 1 deletions

View File

@@ -347,3 +347,19 @@ class ChangeDetectionStore:
self.sync_to_json()
time.sleep(3)
# Go through the datastore path and remove any snapshots that are not mentioned in the index
# This usually is not used, but can be handy.
def remove_unused_snapshots(self):
print ("Removing snapshots from datastore that are not in the index..")
index=[]
for uuid in self.data['watching']:
for id in self.data['watching'][uuid]['history']:
index.append(self.data['watching'][uuid]['history'][str(id)])
import pathlib
# Only in the sub-directories
for item in pathlib.Path(self.datastore_path).rglob("*/*txt"):
if not str(item) in index:
print ("Removing",item)
os.unlink(item)