fix: add event handling for deleted projects

This commit is contained in:
grossmj 2026-08-08 17:27:52 +02:00
parent 544d15c87e
commit bc8e43dfca
No known key found for this signature in database
GPG Key ID: 1E7DD6DBB53FF3D7

View File

@ -29,7 +29,7 @@ try:
except ImportError:
from importlib import resources as importlib_resources
from watchdog.events import FileSystemEventHandler
from watchdog.events import FileSystemEventHandler, DirDeletedEvent, FileDeletedEvent
from watchdog.observers import Observer
from ..config import Config
@ -73,6 +73,9 @@ class _ProjectsDirectoryEventHandler(FileSystemEventHandler):
def on_moved(self, event):
self._handle_event(event)
def on_deleted(self, event: DirDeletedEvent | FileDeletedEvent) -> None:
self._handle_event(event)
def _handle_event(self, event):
if event.is_directory:
# Only react to direct child directories of the projects path
@ -446,6 +449,12 @@ class Controller:
return # Monitor was stopped, skip the scan
try:
await self.load_projects()
# Remove stale projects that no longer exist on disk
for project_id in list(self._projects):
project = self._projects[project_id]
if not os.path.exists(project.path):
log.info(f"Removing stale project '{project.name}' ('{project.path}' no longer exists)")
del self._projects[project.id]
except Exception as e:
log.warning(f"Projects directory rescan failed: {e}")