]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Update consumer.py feature-safer-unlink
authorshamoon <4887959+shamoon@users.noreply.github.com>
Thu, 26 Jun 2025 21:49:08 +0000 (14:49 -0700)
committershamoon <4887959+shamoon@users.noreply.github.com>
Thu, 26 Jun 2025 21:49:08 +0000 (14:49 -0700)
src/documents/consumer.py

index 3c814492a051bf2c086a9f4be19483f9f05d9997..2310935bf6c60f89cc63213932cee173d2b9a601 100644 (file)
@@ -468,7 +468,6 @@ class ConsumerPlugin(
         # now that everything is done, we can start to store the document
         # in the system. This will be a transaction and reasonably fast.
         success = False
-        result = None
         store_exception = None
         try:
             with transaction.atomic():
@@ -572,24 +571,25 @@ class ConsumerPlugin(
                 # Return the most up to date fields
                 document.refresh_from_db()
 
-                result = f"Success. New document id {document.pk} created"
-            elif store_exception:
-                self._fail(
-                    str(store_exception),
-                    f"The following error occurred while storing document "
-                    f"{self.filename} after parsing: {store_exception}",
-                    exc_info=True,
-                    exception=store_exception,
-                )
+                document_parser.cleanup()
+                tempdir.cleanup()
+                return f"Success. New document id {document.pk} created"
             else:
-                self._fail(
-                    ConsumerStatusShortMessage.FAILED,
-                    f"Error occurred while saving {self.filename}.",
-                )
-
-            document_parser.cleanup()
-            tempdir.cleanup()
-            return result
+                document_parser.cleanup()
+                tempdir.cleanup()
+                if store_exception:
+                    self._fail(
+                        str(store_exception),
+                        f"The following error occurred while storing document "
+                        f"{self.filename} after parsing: {store_exception}",
+                        exc_info=True,
+                        exception=store_exception,
+                    )
+                else:
+                    self._fail(
+                        ConsumerStatusShortMessage.FAILED,
+                        f"Error occurred while saving {self.filename}.",
+                    )
 
     def _parse_title_placeholders(self, title: str) -> str:
         local_added = timezone.localtime(timezone.now())