Enhancement: better try to catch db errors before unlink

This commit is contained in:
shamoon 2025-06-23 09:19:28 -07:00
parent 37267f3f04
commit 0f6e9d4343
No known key found for this signature in database

View File

@ -530,8 +530,11 @@ 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
finally:
if success:
# Delete the file only if it was successfully consumed # Delete the file only if it was successfully consumed
self.log.debug(f"Deleting file {self.working_copy}") self.log.debug(f"Deleting file {self.working_copy}")
self.input_doc.original_file.unlink() self.input_doc.original_file.unlink()
@ -548,6 +551,10 @@ class ConsumerPlugin(
if Path(shadow_file).is_file(): if Path(shadow_file).is_file():
self.log.debug(f"Deleting file {shadow_file}") self.log.debug(f"Deleting file {shadow_file}")
Path(shadow_file).unlink() 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(