#36191 closed Bug (fixed)
FileSystemStorage with allow_overwrite=True does not truncate previous file
Reported by: | Gaël UTARD | Owned by: | Gaël UTARD |
---|---|---|---|
Component: | File uploads/storage | Version: | 5.1 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The new allow_overwrite parameter of FileSystemStorage class allows to overwrite an existing file. However, the previous file is not truncated. So, if the previous file was bigger than the new, the file gets corrupted.
It is possible to workaround with :
storage.OS_OPEN_FLAGS = storage.OS_OPEN_FLAGS & ~os.O_EXCL | os.O_TRUNC
Change History (8)
comment:1 by , 6 days ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 6 days ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:3 by , 6 days ago
Has patch: | set |
---|
comment:4 by , 6 days ago
Jacob, thanks for your confirmation of the bug, and confirmation of the fix I had in mind.
I pushed a PR, including your idea to assert the length of both contents in the test.
It's my first contribution to Django. I read the docs. I hope I did it right.
comment:5 by , 4 days ago
Triage Stage: | Accepted → Ready for checkin |
---|
Note:
See TracTickets
for help on using tickets.
Thanks for the report, reproduced by adjusting this existing test case:
tests/file_storage/tests.py
"second content"Test passes with the suggested patch:
Would you like to submit a PR?