1
0
mirror of https://github.com/django/django.git synced 2024-12-24 18:16:19 +00:00

Fixed #7683: Try not to delete uploaded files before moving them, and don't wig out of someone else does. Patch from screeley and spaetz.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8217 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss 2008-08-05 17:43:05 +00:00
parent 34008aaeb0
commit 98d8acf33f
2 changed files with 13 additions and 3 deletions

View File

@ -202,11 +202,21 @@ class TemporaryUploadedFile(UploadedFile):
def read(self, *args): return self._file.read(*args)
def seek(self, offset): return self._file.seek(offset)
def write(self, s): return self._file.write(s)
def close(self): return self._file.close()
def __iter__(self): return iter(self._file)
def readlines(self, size=None): return self._file.readlines(size)
def xreadlines(self): return self._file.xreadlines()
def close(self):
try:
return self._file.close()
except OSError, e:
if e.errno == 2:
# Means the file was moved or deleted before the tempfile could unlink it.
# Still sets self._file.close_called and calls self._file.file.close()
# before the exception
return
else:
raise e
class InMemoryUploadedFile(UploadedFile):
"""
A file uploaded into memory (i.e. stream-to-memory).

View File

@ -529,8 +529,8 @@ class Model(object):
full_filename = self._get_FIELD_filename(field)
if hasattr(raw_field, 'temporary_file_path'):
# This file has a file path that we can move.
raw_field.close()
file_move_safe(raw_field.temporary_file_path(), full_filename)
raw_field.close()
else:
# This is a normal uploadedfile that we can stream.
fp = open(full_filename, 'wb')