Ticket #7844: 7844.diff

File 7844.diff, 1.3 KB (added by scum, 16 years ago)

Added a optional parameter to get_filename fixingthe race condition. Not as pretty, but the only way I can think to do it right.

  • db/models/base.py

     
    505505        if filename is None:
    506506            filename = raw_field.file_name
    507507
    508         filename = field.get_filename(filename)
     508        filename = field.get_filename(filename, directory)
    509509
    510510        # If the filename already exists, keep adding an underscore to the name
    511511        # of the file until the filename doesn't exist.
  • db/models/fields/__init__.py

     
    862862    def get_directory_name(self):
    863863        return os.path.normpath(force_unicode(datetime.datetime.now().strftime(smart_str(self.upload_to))))
    864864
    865     def get_filename(self, filename):
     865    def get_filename(self, filename, directory=None):
    866866        from django.utils.text import get_valid_filename
    867         f = os.path.join(self.get_directory_name(), get_valid_filename(os.path.basename(filename)))
     867        if not directory:
     868            directory = self.get_directory_name()
     869        f = os.path.join(directory, get_valid_filename(os.path.basename(filename)))
    868870        return os.path.normpath(f)
    869871
    870872    def save_form_data(self, instance, data):
Back to Top