From 17b0bcf3a0a79045e8dedfcbf2b47f4e2e724f93 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Sun, 9 Apr 2023 13:37:58 -0500 Subject: [PATCH] Add strict set of events to monitor --- dmoj/monitor.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dmoj/monitor.py b/dmoj/monitor.py index 020e8569c..664564fdd 100644 --- a/dmoj/monitor.py +++ b/dmoj/monitor.py @@ -10,7 +10,13 @@ try: from watchdog.observers import Observer - from watchdog.events import FileSystemEventHandler + from watchdog.events import ( + FileSystemEventHandler, + EVENT_TYPE_MOVED, + EVENT_TYPE_DELETED, + EVENT_TYPE_MODIFIED, + EVENT_TYPE_CREATED, + ) has_watchdog_installed = True except ImportError: @@ -52,11 +58,20 @@ def run(self): class SendProblemsHandler(FileSystemEventHandler): + ALLOWED_EVENT_TYPES = ( + EVENT_TYPE_MOVED, + EVENT_TYPE_DELETED, + EVENT_TYPE_MODIFIED, + EVENT_TYPE_CREATED, + ) + def __init__(self, refresher=None): self.refresher = refresher self.callback = None def on_any_event(self, event): + if event.event_type not in self.ALLOWED_EVENT_TYPES: + return if self.callback is not None: self.callback() if self.refresher is not None: