diff -ru Django-1.5a1/django/core/files/move.py Django-1.5a1-locks/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-1.5a1/django/core/files/storage.py Django-1.5a1-locks/django/core/files/storage.py
|
old
|
new
|
|
| 146 | 146 | Standard filesystem storage |
| 147 | 147 | """ |
| 148 | 148 | |
| 149 | | def __init__(self, location=None, base_url=None): |
| | 149 | def __init__(self, location=None, base_url=None, locks=locks): |
| 150 | 150 | if location is None: |
| 151 | 151 | location = settings.MEDIA_ROOT |
| 152 | 152 | self.base_location = location |
| … |
… |
|
| 154 | 154 | if base_url is None: |
| 155 | 155 | base_url = settings.MEDIA_URL |
| 156 | 156 | self.base_url = base_url |
| | 157 | self.locks = locks |
| 157 | 158 | |
| 158 | 159 | def _open(self, name, mode='rb'): |
| 159 | 160 | return File(open(self.path(name), mode)) |
| … |
… |
|
| 185 | 186 | try: |
| 186 | 187 | # This file has a file path that we can move. |
| 187 | 188 | 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) |
| 189 | 190 | content.close() |
| 190 | 191 | |
| 191 | 192 | # This is a normal uploadedfile that we can stream. |
| … |
… |
|
| 197 | 198 | # The current umask value is masked out by os.open! |
| 198 | 199 | fd = os.open(full_path, flags, 0o666) |
| 199 | 200 | try: |
| 200 | | locks.lock(fd, locks.LOCK_EX) |
| | 201 | self.locks.lock(fd, self.locks.LOCK_EX) |
| 201 | 202 | _file = None |
| 202 | 203 | for chunk in content.chunks(): |
| 203 | 204 | if _file is None: |
| … |
… |
|
| 205 | 206 | _file = os.fdopen(fd, mode) |
| 206 | 207 | _file.write(chunk) |
| 207 | 208 | finally: |
| 208 | | locks.unlock(fd) |
| | 209 | self.locks.unlock(fd) |
| 209 | 210 | if _file is not None: |
| 210 | 211 | _file.close() |
| 211 | 212 | else: |