File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import asyncio
22import logging
3+ import os
34from abc import ABC , abstractmethod
45from typing import Optional , Self , Sequence
56
@@ -155,3 +156,21 @@ def replace_config(self, new_config: Config) -> Self:
155156 )
156157 self ._configs = new_config
157158 return self
159+
160+ async def check_orphanes (self ) -> int :
161+ """
162+ Check for files that are in the database, but no longer on the disk, and remove them.
163+ """
164+
165+ orphanes : list [str ] = []
166+ database_files = (await self .list (ResultType .document )).files
167+ for file in database_files :
168+ path = file .path
169+ if not os .path .isfile (path ):
170+ orphanes .append (path )
171+ logger .debug (f"Discovered orphaned file: { path } " )
172+
173+ self .update_config (Config (rm_paths = orphanes ))
174+ await self .delete ()
175+
176+ return len (orphanes )
You can’t perform that action at this time.
0 commit comments