mirror of
https://github.com/django/django.git
synced 2025-04-13 03:52:20 +00:00
Fixed #36191 -- Truncated the overwritten file content in FileSystemStorage.
This commit is contained in:
parent
2fa1f99ab4
commit
0d1dd6bba0
1
AUTHORS
1
AUTHORS
@ -369,6 +369,7 @@ answer newbie questions, and generally made Django that much better:
|
||||
Fraser Nevett <mail@nevett.org>
|
||||
Gabriel Grant <g@briel.ca>
|
||||
Gabriel Hurley <gabriel@strikeawe.com>
|
||||
Gaël Utard
|
||||
gandalf@owca.info
|
||||
Garry Lawrence
|
||||
Garry Polley <garrympolley@gmail.com>
|
||||
|
@ -113,7 +113,7 @@ class FileSystemStorage(Storage, StorageSettingsMixin):
|
||||
| getattr(os, "O_BINARY", 0)
|
||||
)
|
||||
if self._allow_overwrite:
|
||||
open_flags = open_flags & ~os.O_EXCL
|
||||
open_flags = open_flags & ~os.O_EXCL | os.O_TRUNC
|
||||
fd = os.open(full_path, open_flags, 0o666)
|
||||
_file = None
|
||||
try:
|
||||
|
@ -12,3 +12,7 @@ Bugfixes
|
||||
* Fixed a bug in Django 5.1 where the ``{% querystring %}`` template tag
|
||||
returned an empty string rather than ``"?"`` when all parameters had been
|
||||
removed from the query string (:ticket:`36182`).
|
||||
|
||||
* Fixed a bug in Django 5.1 where ``FileSystemStorage``, with
|
||||
``allow_overwrite`` set to ``True``, did not truncate the overwritten file
|
||||
content (:ticket:`36191`).
|
||||
|
@ -634,6 +634,18 @@ class OverwritingStorageTests(FileStorageTests):
|
||||
finally:
|
||||
self.storage.delete(name)
|
||||
|
||||
def test_save_overwrite_behavior_truncate(self):
|
||||
name = "test.file"
|
||||
original_content = b"content extra extra extra"
|
||||
new_smaller_content = b"content"
|
||||
self.storage.save(name, ContentFile(original_content))
|
||||
try:
|
||||
self.storage.save(name, ContentFile(new_smaller_content))
|
||||
with self.storage.open(name) as fp:
|
||||
self.assertEqual(fp.read(), new_smaller_content)
|
||||
finally:
|
||||
self.storage.delete(name)
|
||||
|
||||
def test_save_overwrite_behavior_temp_file(self):
|
||||
"""Saving to same file name twice overwrites the first file."""
|
||||
name = "test.file"
|
||||
|
Loading…
x
Reference in New Issue
Block a user