From fbe3b24d01eae31ca1fb026c040e8ad952c19e0c Mon Sep 17 00:00:00 2001 From: Wicky Rampersad Date: Thu, 16 Apr 2020 15:56:52 +0200 Subject: [PATCH 1/2] Prevent Paperless crash when consume folder is unavailable --- src/documents/consumer.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/documents/consumer.py b/src/documents/consumer.py index 4e9f17116..aecf45c21 100644 --- a/src/documents/consumer.py +++ b/src/documents/consumer.py @@ -87,20 +87,27 @@ def consume_new_files(self): """ ignored_files = [] files = [] - for entry in os.scandir(self.consume): - if entry.is_file(): - file = (entry.path, entry.stat().st_mtime) - if file in self._ignore: - ignored_files.append(file) + try: + for entry in os.scandir(self.consume): + if entry.is_file(): + file = (entry.path, entry.stat().st_mtime) + if file in self._ignore: + ignored_files.append(file) + else: + files.append(file) else: - files.append(file) - else: - self.logger.warning( - "Skipping %s as it is not a file", - entry.path - ) - - if not files: + self.logger.warning( + "Skipping %s as it is not a file", + entry.path + ) + + if not files: + return + + except OSError: + self.logger.warning( + "Consume folder is unavailable." + ) return # Set _ignore to only include files that still exist. From 9db8b90a2aff7cc48041e263d842821e14b5dc3e Mon Sep 17 00:00:00 2001 From: w0ndersp00n Date: Thu, 16 Apr 2020 18:38:28 +0000 Subject: [PATCH 2/2] Update consumer.py --- src/documents/consumer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/documents/consumer.py b/src/documents/consumer.py index aecf45c21..bbe8d9b92 100644 --- a/src/documents/consumer.py +++ b/src/documents/consumer.py @@ -103,7 +103,7 @@ def consume_new_files(self): if not files: return - + except OSError: self.logger.warning( "Consume folder is unavailable."