Fix: Ensure export filenames fit within 143-character limit
The eCryptfs filesystem imposes a filename length limit of 143 characters. This limit still applies on some systems, such as Synology and QNAP NAS devices when using encrypted folders. When saving documents with long names, Paperless-ngx triggers a warning (`[Errno 36] File name too long`), but it gracefully falls back to a default or truncated name. However, the `document_exporter` crashes when encountering such filenames during export. This change ensures that exported document base names are capped at 120 characters, leaving room for extensions and suffixes and keeping the total filename length within 143 characters. Using the document exported with the "--delete" parameter will take care of eventual old files with a long name, if the filesystem supported it.
This commit is contained in:
@@ -5,6 +5,7 @@ import tempfile
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from auditlog.context import disable_auditlog
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
@@ -1130,6 +1131,20 @@ class TestFilenameGeneration(DirectoriesMixin, TestCase):
|
||||
self.assertEqual(generate_filename(owned_doc), "user1/The Title.pdf")
|
||||
self.assertEqual(generate_filename(no_owner_doc), "none/does matter.pdf")
|
||||
|
||||
@override_settings(
|
||||
FILENAME_FORMAT="{title}",
|
||||
)
|
||||
def test_generate_shorted_file_name(self):
|
||||
doc = Document.objects.create(
|
||||
mime_type="application/pdf",
|
||||
title="This file has a very long filename that will exceed filename limits on some obscure filesystems, such as eCryptfs which accepts up to 143 characters",
|
||||
checksum="3",
|
||||
)
|
||||
self.assertEqual(len(generate_filename(doc)), 152)
|
||||
self.assertLessEqual(len(generate_filename(doc, basename_max_length=120)), 143)
|
||||
with pytest.raises(ValueError):
|
||||
generate_filename(doc, basename_max_length=19)
|
||||
|
||||
@override_settings(
|
||||
FILENAME_FORMAT="{original_name}",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user