Ticket #7683: 7683.5.diff

File 7683.5.diff, 1.9 KB (added by spaetz, 16 years ago)

same as patch 7683.3, but just catching errno ==2 (missing file)

  • django/db/models/base.py

     
    527527        full_filename = self._get_FIELD_filename(field)
    528528        if hasattr(raw_field, 'temporary_file_path'):
    529529            # This file has a file path that we can move.
     530            file_move_safe(raw_field.temporary_file_path(), full_filename)
    530531            raw_field.close()
    531             file_move_safe(raw_field.temporary_file_path(), full_filename)
    532532        else:
    533533            # This is a normal uploadedfile that we can stream.
    534534            fp = open(full_filename, 'wb')
  • django/core/files/uploadedfile.py

     
    201201    def read(self, *args):          return self._file.read(*args)
    202202    def seek(self, offset):         return self._file.seek(offset)
    203203    def write(self, s):             return self._file.write(s)
    204     def close(self):                return self._file.close()
    205204    def __iter__(self):             return iter(self._file)
    206205    def readlines(self, size=None): return self._file.readlines(size)
    207206    def xreadlines(self):           return self._file.xreadlines()
    208 
     207    def close(self):
     208        try:
     209            return self._file.close()
     210        except OSError, e:
     211            if e.errno == 2:
     212                # Means the file was moved or deleted before the tempfile could unlink it.
     213                # Still sets self._file.close_called and calls self._file.file.close()
     214                # before the exception
     215                return
     216            else:
     217                raise e
     218       
    209219class InMemoryUploadedFile(UploadedFile):
    210220    """
    211221    A file uploaded into memory (i.e. stream-to-memory).
Back to Top