diff -ru django/core/files/move.py /Library/Python/2.5/site-packages/django/core/files/move.py
|
old
|
new
|
|
| 35 | 35 | return (os.path.normcase(os.path.abspath(src)) == |
| 36 | 36 | os.path.normcase(os.path.abspath(dst))) |
| 37 | 37 | |
| 38 | | def file_move_safe(old_file_name, new_file_name, chunk_size = 1024*64, allow_overwrite=False): |
| | 38 | def file_move_safe(old_file_name, new_file_name, chunk_size = 1024*64, allow_overwrite=False, locks=locks): |
| 39 | 39 | """ |
| 40 | 40 | Moves a file from one location to another in the safest way possible. |
| 41 | 41 | |
diff -ru django/core/files/storage.py /Library/Python/2.5/site-packages/django/core/files/storage.py
|
old
|
new
|
|
| 121 | 121 | Standard filesystem storage |
| 122 | 122 | """ |
| 123 | 123 | |
| 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): |
| 125 | 125 | self.location = os.path.abspath(location) |
| 126 | 126 | self.base_url = base_url |
| | 127 | self.locks = locks |
| 127 | 128 | |
| 128 | 129 | def _open(self, name, mode='rb'): |
| 129 | 130 | return File(open(self.path(name), mode)) |
| … |
… |
|
| 147 | 148 | try: |
| 148 | 149 | # This file has a file path that we can move. |
| 149 | 150 | 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) |
| 151 | 152 | content.close() |
| 152 | 153 | |
| 153 | 154 | # This is a normal uploadedfile that we can stream. |
| … |
… |
|
| 156 | 157 | # OSError if the file already exists before we open it. |
| 157 | 158 | fd = os.open(full_path, os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, 'O_BINARY', 0)) |
| 158 | 159 | try: |
| 159 | | locks.lock(fd, locks.LOCK_EX) |
| | 160 | self.locks.lock(fd, self.locks.LOCK_EX) |
| 160 | 161 | for chunk in content.chunks(): |
| 161 | 162 | os.write(fd, chunk) |
| 162 | 163 | finally: |
| 163 | | locks.unlock(fd) |
| | 164 | self.locks.unlock(fd) |
| 164 | 165 | os.close(fd) |
| 165 | 166 | except OSError, e: |
| 166 | 167 | if e.errno == errno.EEXIST: |