Ticket #9433: inject_locks.patch

File inject_locks.patch, 2.5 KB (added by rndblnch, 16 years ago)

makes the locks dependency explicit

  • django/core/files/move.py

    diff -ru django/core/files/move.py /Library/Python/2.5/site-packages/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/core/files/storage.py /Library/Python/2.5/site-packages/django/core/files/storage.py
    old new  
    121121    Standard filesystem storage
    122122    """
    123123
    124     def __init__(self, location=settings.MEDIA_ROOT, base_url=settings.MEDIA_URL):
     124    def __init__(self, location=settings.MEDIA_ROOT, base_url=settings.MEDIA_URL, locks=locks):
    125125        self.location = os.path.abspath(location)
    126126        self.base_url = base_url
     127        self.locks = locks
    127128
    128129    def _open(self, name, mode='rb'):
    129130        return File(open(self.path(name), mode))
     
    147148            try:
    148149                # This file has a file path that we can move.
    149150                if hasattr(content, 'temporary_file_path'):
    150                     file_move_safe(content.temporary_file_path(), full_path)
     151                    file_move_safe(content.temporary_file_path(), full_path, locks=self.locks)
    151152                    content.close()
    152153
    153154                # This is a normal uploadedfile that we can stream.
     
    156157                    # OSError if the file already exists before we open it.
    157158                    fd = os.open(full_path, os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, 'O_BINARY', 0))
    158159                    try:
    159                         locks.lock(fd, locks.LOCK_EX)
     160                        self.locks.lock(fd, self.locks.LOCK_EX)
    160161                        for chunk in content.chunks():
    161162                            os.write(fd, chunk)
    162163                    finally:
    163                         locks.unlock(fd)
     164                        self.locks.unlock(fd)
    164165                        os.close(fd)
    165166            except OSError, e:
    166167                if e.errno == errno.EEXIST:
Back to Top