mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Check if document file exist before deletion
This commit is contained in:
parent
1ce6c6e2c5
commit
79976d18ab
@ -410,6 +410,7 @@ def delete_empty_directory(directory):
|
||||
# Directory not empty
|
||||
pass
|
||||
|
||||
|
||||
@receiver(models.signals.m2m_changed, sender=Document.tags.through)
|
||||
@receiver(models.signals.post_save, sender=Document)
|
||||
def update_filename(sender, instance, **kwargs):
|
||||
@ -460,7 +461,13 @@ def delete_files(sender, instance, **kwargs):
|
||||
|
||||
# Remove the document
|
||||
old_file = instance.filename_to_path(instance.filename)
|
||||
os.remove(old_file)
|
||||
|
||||
if os.path.isfile(old_file):
|
||||
os.remove(old_file)
|
||||
else:
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.warning("Deleted document " + str(instance.id) + " but file " +
|
||||
old_file + " was no longer present")
|
||||
|
||||
# And remove the directory (if applicable)
|
||||
old_dir = os.path.dirname(instance.filename)
|
||||
|
Loading…
x
Reference in New Issue
Block a user