From 18f65936660029d2a10f423882b10a46f19ff104 Mon Sep 17 00:00:00 2001 From: mungai-njoroge Date: Tue, 18 Jul 2023 16:53:06 +0300 Subject: [PATCH] handle the FileNotFoundError for os.path.getsize on watchdogg --- app/lib/colorlib.py | 2 +- app/lib/watchdogg.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/lib/colorlib.py b/app/lib/colorlib.py index 6c143b8..28c90dd 100644 --- a/app/lib/colorlib.py +++ b/app/lib/colorlib.py @@ -53,7 +53,7 @@ class ProcessAlbumColors: """ def __init__(self) -> None: - albums = [a for a in AlbumStore.albums if a is None or len(a.colors) == 0] + albums = [a for a in AlbumStore.albums if a is not None and len(a.colors) == 0] with SQLiteManager() as cur: try: diff --git a/app/lib/watchdogg.py b/app/lib/watchdogg.py index abcaa11..bb77bf9 100644 --- a/app/lib/watchdogg.py +++ b/app/lib/watchdogg.py @@ -246,9 +246,13 @@ class Handler(PatternMatchingEventHandler): """ Fired when a supported file is created. """ + try: + self.file_sizes[event.src_path] = os.path.getsize(event.src_path) + except FileNotFoundError: + return + self.files_to_process.append(event.src_path) self.files_to_process_windows.append(event.src_path) - self.file_sizes[event.src_path] = os.path.getsize(event.src_path) def on_deleted(self, event): """ @@ -304,7 +308,12 @@ class Handler(PatternMatchingEventHandler): return # Check if file write operation is complete - current_size = os.path.getsize(event.src_path) + try: + current_size = os.path.getsize(event.src_path) + except FileNotFoundError: + # File was deleted or moved + return + previous_size = self.file_sizes.get(event.src_path, -1) if current_size == previous_size: @@ -315,7 +324,7 @@ class Handler(PatternMatchingEventHandler): try: current_size = os.path.getsize(event.src_path) except FileNotFoundError: - # File was deleted + # File was deleted or moved return if current_size == previous_size: