Ticket #9433: inject_locks_Django-1.5a1.patch

File inject_locks_Django-1.5a1.patch, 2.7 KB (added by rndblnch, 2 years ago)

patch bumped to 1.5a1

  • django/core/files/move.py

    diff -ru Django-1.5a1/django/core/files/move.py Django-1.5a1-locks/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.5a1/django/core/files/storage.py Django-1.5a1-locks/django/core/files/storage.py
    old new  
    146146    Standard filesystem storage
    147147    """
    148148
    149     def __init__(self, location=None, base_url=None):
     149    def __init__(self, location=None, base_url=None, locks=locks):
    150150        if location is None:
    151151            location = settings.MEDIA_ROOT
    152152        self.base_location = location
     
    154154        if base_url is None:
    155155            base_url = settings.MEDIA_URL
    156156        self.base_url = base_url
     157        self.locks = locks
    157158
    158159    def _open(self, name, mode='rb'):
    159160        return File(open(self.path(name), mode))
     
    185186            try:
    186187                # This file has a file path that we can move.
    187188                if hasattr(content, 'temporary_file_path'):
    188                     file_move_safe(content.temporary_file_path(), full_path)
     189                    file_move_safe(content.temporary_file_path(), full_path, self.locks)
    189190                    content.close()
    190191
    191192                # This is a normal uploadedfile that we can stream.
     
    197198                    # The current umask value is masked out by os.open!
    198199                    fd = os.open(full_path, flags, 0o666)
    199200                    try:
    200                         locks.lock(fd, locks.LOCK_EX)
     201                        self.locks.lock(fd, self.locks.LOCK_EX)
    201202                        _file = None
    202203                        for chunk in content.chunks():
    203204                            if _file is None:
     
    205206                                _file = os.fdopen(fd, mode)
    206207                            _file.write(chunk)
    207208                    finally:
    208                         locks.unlock(fd)
     209                        self.locks.unlock(fd)
    209210                        if _file is not None:
    210211                            _file.close()
    211212                        else:
Back to Top