mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
locking media directory while deleting files
This commit is contained in:
parent
6003122b06
commit
70cbdbf23b
@ -171,29 +171,30 @@ def run_post_consume_script(sender, document, **kwargs):
|
|||||||
|
|
||||||
@receiver(models.signals.post_delete, sender=Document)
|
@receiver(models.signals.post_delete, sender=Document)
|
||||||
def cleanup_document_deletion(sender, instance, using, **kwargs):
|
def cleanup_document_deletion(sender, instance, using, **kwargs):
|
||||||
for f in (instance.source_path,
|
with FileLock(settings.MEDIA_LOCK):
|
||||||
instance.archive_path,
|
for f in (instance.source_path,
|
||||||
instance.thumbnail_path):
|
instance.archive_path,
|
||||||
if os.path.isfile(f):
|
instance.thumbnail_path):
|
||||||
try:
|
if os.path.isfile(f):
|
||||||
os.unlink(f)
|
try:
|
||||||
logging.getLogger(__name__).debug(
|
os.unlink(f)
|
||||||
f"Deleted file {f}.")
|
logging.getLogger(__name__).debug(
|
||||||
except OSError as e:
|
f"Deleted file {f}.")
|
||||||
logging.getLogger(__name__).warning(
|
except OSError as e:
|
||||||
f"While deleting document {str(instance)}, the file "
|
logging.getLogger(__name__).warning(
|
||||||
f"{f} could not be deleted: {e}"
|
f"While deleting document {str(instance)}, the file "
|
||||||
)
|
f"{f} could not be deleted: {e}"
|
||||||
|
)
|
||||||
|
|
||||||
delete_empty_directories(
|
delete_empty_directories(
|
||||||
os.path.dirname(instance.source_path),
|
os.path.dirname(instance.source_path),
|
||||||
root=settings.ORIGINALS_DIR
|
root=settings.ORIGINALS_DIR
|
||||||
)
|
)
|
||||||
|
|
||||||
delete_empty_directories(
|
delete_empty_directories(
|
||||||
os.path.dirname(instance.archive_path),
|
os.path.dirname(instance.archive_path),
|
||||||
root=settings.ARCHIVE_DIR
|
root=settings.ARCHIVE_DIR
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def validate_move(instance, old_path, new_path):
|
def validate_move(instance, old_path, new_path):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user