Description: Fix failing test when AUFS is in use
AUFS only supports filenames up to 242 characters and a test
was wrongly assuming that a 255 characters filename would be possible.
Bug: https://code.djangoproject.com/ticket/24826
Author: Claude Paroz <claude@2xlibre.net> with changes by Raphaël Hertzog <hertzog@debian.org>
a
|
b
|
from django.utils.crypto import get_rand
|
13 | 13 | from django.utils.deconstruct import deconstructible |
14 | 14 | from django.utils.deprecation import RemovedInDjango20Warning |
15 | 15 | from django.utils.encoding import filepath_to_uri, force_text |
16 | | from django.utils.functional import LazyObject |
| 16 | from django.utils.functional import LazyObject, cached_property |
17 | 17 | from django.utils.module_loading import import_string |
18 | 18 | from django.utils.six.moves.urllib.parse import urljoin |
19 | 19 | from django.utils.text import get_valid_filename |
… |
… |
class Storage(object):
|
27 | 27 | storage systems can inherit or override, as necessary. |
28 | 28 | """ |
29 | 29 | |
| 30 | MAX_FILENAME_LENGTH = 255 # Should be safe on most backends |
| 31 | |
30 | 32 | # The following methods represent a public interface to private methods. |
31 | 33 | # These shouldn't be overridden by subclasses unless absolutely necessary. |
32 | 34 | |
… |
… |
class FileSystemStorage(Storage):
|
198 | 200 | else settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS |
199 | 201 | ) |
200 | 202 | |
| 203 | @cached_property |
| 204 | def MAX_FILENAME_LENGTH(self): |
| 205 | dir_to_test = self.location |
| 206 | while not os.path.exists(dir_to_test): |
| 207 | dir_to_test = os.path.dirname(dir_to_test) |
| 208 | try: |
| 209 | return os.pathconf(dir_to_test, 'PC_NAME_MAX') |
| 210 | except Exception: |
| 211 | return Storage.MAX_FILENAME_LENGTH |
| 212 | |
201 | 213 | def _open(self, name, mode='rb'): |
202 | 214 | return File(open(self.path(name), mode)) |
203 | 215 | |