mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-18 17:34:39 -05:00
Try this
This commit is contained in:
parent
0f6e9d4343
commit
f819d8025c
@ -467,6 +467,7 @@ class ConsumerPlugin(
|
|||||||
)
|
)
|
||||||
# now that everything is done, we can start to store the document
|
# now that everything is done, we can start to store the document
|
||||||
# in the system. This will be a transaction and reasonably fast.
|
# in the system. This will be a transaction and reasonably fast.
|
||||||
|
success = False
|
||||||
try:
|
try:
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
# store the document.
|
# store the document.
|
||||||
@ -530,31 +531,8 @@ class ConsumerPlugin(
|
|||||||
# Don't save with the lock active. Saving will cause the file
|
# Don't save with the lock active. Saving will cause the file
|
||||||
# renaming logic to acquire the lock as well.
|
# renaming logic to acquire the lock as well.
|
||||||
# This triggers things like file renaming
|
# This triggers things like file renaming
|
||||||
try:
|
document.save()
|
||||||
document.save()
|
success = True
|
||||||
success = True
|
|
||||||
finally:
|
|
||||||
if success:
|
|
||||||
# Delete the file only if it was successfully consumed
|
|
||||||
self.log.debug(f"Deleting file {self.working_copy}")
|
|
||||||
self.input_doc.original_file.unlink()
|
|
||||||
self.working_copy.unlink()
|
|
||||||
if self.unmodified_original is not None: # pragma: no cover
|
|
||||||
self.unmodified_original.unlink()
|
|
||||||
|
|
||||||
# https://github.com/jonaswinkler/paperless-ng/discussions/1037
|
|
||||||
shadow_file = (
|
|
||||||
Path(self.input_doc.original_file).parent
|
|
||||||
/ f"._{Path(self.input_doc.original_file).name}"
|
|
||||||
)
|
|
||||||
|
|
||||||
if Path(shadow_file).is_file():
|
|
||||||
self.log.debug(f"Deleting file {shadow_file}")
|
|
||||||
Path(shadow_file).unlink()
|
|
||||||
else:
|
|
||||||
self.log.warning(
|
|
||||||
f"Document was not saved. Skipping file deletion for {self.filename}",
|
|
||||||
)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._fail(
|
self._fail(
|
||||||
@ -565,25 +543,49 @@ class ConsumerPlugin(
|
|||||||
exception=e,
|
exception=e,
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
|
if success:
|
||||||
|
# Delete the file only if it was successfully consumed
|
||||||
|
self.log.debug(f"Deleting file {self.working_copy}")
|
||||||
|
self.input_doc.original_file.unlink()
|
||||||
|
self.working_copy.unlink()
|
||||||
|
if self.unmodified_original is not None: # pragma: no cover
|
||||||
|
self.unmodified_original.unlink()
|
||||||
|
|
||||||
|
# https://github.com/jonaswinkler/paperless-ng/discussions/1037
|
||||||
|
shadow_file = (
|
||||||
|
Path(self.input_doc.original_file).parent
|
||||||
|
/ f"._{Path(self.input_doc.original_file).name}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if Path(shadow_file).is_file():
|
||||||
|
self.log.debug(f"Deleting file {shadow_file}")
|
||||||
|
Path(shadow_file).unlink()
|
||||||
|
|
||||||
|
self.run_post_consume_script(document)
|
||||||
|
|
||||||
|
self.log.info(f"Document {document} consumption finished")
|
||||||
|
|
||||||
|
self._send_progress(
|
||||||
|
100,
|
||||||
|
100,
|
||||||
|
ProgressStatusOptions.SUCCESS,
|
||||||
|
ConsumerStatusShortMessage.FINISHED,
|
||||||
|
document.id,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Return the most up to date fields
|
||||||
|
document.refresh_from_db()
|
||||||
|
|
||||||
|
result = f"Success. New document id {document.pk} created"
|
||||||
|
else:
|
||||||
|
self._fail(
|
||||||
|
ConsumerStatusShortMessage.FAILED,
|
||||||
|
f"Document {self.filename} was not saved.",
|
||||||
|
)
|
||||||
|
|
||||||
document_parser.cleanup()
|
document_parser.cleanup()
|
||||||
tempdir.cleanup()
|
tempdir.cleanup()
|
||||||
|
return result
|
||||||
self.run_post_consume_script(document)
|
|
||||||
|
|
||||||
self.log.info(f"Document {document} consumption finished")
|
|
||||||
|
|
||||||
self._send_progress(
|
|
||||||
100,
|
|
||||||
100,
|
|
||||||
ProgressStatusOptions.SUCCESS,
|
|
||||||
ConsumerStatusShortMessage.FINISHED,
|
|
||||||
document.id,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Return the most up to date fields
|
|
||||||
document.refresh_from_db()
|
|
||||||
|
|
||||||
return f"Success. New document id {document.pk} created"
|
|
||||||
|
|
||||||
def _parse_title_placeholders(self, title: str) -> str:
|
def _parse_title_placeholders(self, title: str) -> str:
|
||||||
local_added = timezone.localtime(timezone.now())
|
local_added = timezone.localtime(timezone.now())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user