Ticket #9433: inject_locks_Django-1.1.1.patch

File inject_locks_Django-1.1.1.patch, 2.6 KB (added by rndblnch, 6 years ago)

revised patch against django 1.1.1

  • django/core/files/move.py

    Only in Django-1.1.1.patched: build
    diff -ru Django-1.1.1/django/core/files/move.py Django-1.1.1.patched/django/core/files/move.py
    old new  
    3535    return (os.path.normcase(os.path.abspath(src)) ==
    3636            os.path.normcase(os.path.abspath(dst)))
    3737
    38 def file_move_safe(old_file_name, new_file_name, chunk_size = 1024*64, allow_overwrite=False):
     38def file_move_safe(old_file_name, new_file_name, chunk_size = 1024*64, allow_overwrite=False, locks=locks):
    3939    """
    4040    Moves a file from one location to another in the safest way possible.
    4141
  • django/core/files/storage.py

    diff -ru Django-1.1.1/django/core/files/storage.py Django-1.1.1.patched/django/core/files/storage.py
    old new  
    127127    Standard filesystem storage
    128128    """
    129129
    130     def __init__(self, location=None, base_url=None):
     130    def __init__(self, location=None, base_url=None, locks=locks):
    131131        if location is None:
    132132            location = settings.MEDIA_ROOT
    133133        if base_url is None:
    134134            base_url = settings.MEDIA_URL
    135135        self.location = os.path.abspath(location)
    136136        self.base_url = base_url
     137        self.locks = locks
    137138
    138139    def _open(self, name, mode='rb'):
    139140        return File(open(self.path(name), mode))
     
    157158            try:
    158159                # This file has a file path that we can move.
    159160                if hasattr(content, 'temporary_file_path'):
    160                     file_move_safe(content.temporary_file_path(), full_path)
     161                    file_move_safe(content.temporary_file_path(), full_path, self.locks)
    161162                    content.close()
    162163
    163164                # This is a normal uploadedfile that we can stream.
     
    166167                    # OSError if the file already exists before we open it.
    167168                    fd = os.open(full_path, os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, 'O_BINARY', 0))
    168169                    try:
    169                         locks.lock(fd, locks.LOCK_EX)
     170                        self.locks.lock(fd, self.locks.LOCK_EX)
    170171                        for chunk in content.chunks():
    171172                            os.write(fd, chunk)
    172173                    finally:
    173                         locks.unlock(fd)
     174                        self.locks.unlock(fd)
    174175                        os.close(fd)
    175176            except OSError, e:
    176177                if e.errno == errno.EEXIST:
Back to Top