From c29b47319f24f6cb0031142d5a48b78708ed3bed Mon Sep 17 00:00:00 2001 From: croneter Date: Fri, 6 Jul 2018 21:44:08 +0200 Subject: [PATCH] Drop directory filesystem events immediately --- resources/lib/playlists.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/resources/lib/playlists.py b/resources/lib/playlists.py index d8bd1712..ac23dc91 100644 --- a/resources/lib/playlists.py +++ b/resources/lib/playlists.py @@ -571,6 +571,22 @@ class PlaylistEventhandler(events.FileSystemEventHandler): pass +class PlaylistQueue(OrderedSetQueue): + """ + OrderedSetQueue that drops all directory events immediately + """ + def _put(self, item): + if item[0].is_directory: + self.unfinished_tasks -= 1 + elif item not in self._set_of_items: + Queue.Queue._put(self, item) + self._set_of_items.add(item) + else: + # `put` increments `unfinished_tasks` even if we did not put + # anything into the queue here + self.unfinished_tasks -= 1 + + class PlaylistObserver(Observer): """ PKC implementation, overriding the dispatcher. PKC will wait for the @@ -582,7 +598,7 @@ class PlaylistObserver(Observer): super(PlaylistObserver, self).__init__(*args, **kwargs) # Drop the same events that get into the queue even if there are other # events in between these similar events - self._event_queue = OrderedSetQueue() + self._event_queue = PlaylistQueue() @staticmethod def _pkc_similar_events(event1, event2):