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
|
|
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.1.1/django/core/files/storage.py Django-1.1.1.patched/django/core/files/storage.py
old
|
new
|
|
127 | 127 | Standard filesystem storage |
128 | 128 | """ |
129 | 129 | |
130 | | def __init__(self, location=None, base_url=None): |
| 130 | def __init__(self, location=None, base_url=None, locks=locks): |
131 | 131 | if location is None: |
132 | 132 | location = settings.MEDIA_ROOT |
133 | 133 | if base_url is None: |
134 | 134 | base_url = settings.MEDIA_URL |
135 | 135 | self.location = os.path.abspath(location) |
136 | 136 | self.base_url = base_url |
| 137 | self.locks = locks |
137 | 138 | |
138 | 139 | def _open(self, name, mode='rb'): |
139 | 140 | return File(open(self.path(name), mode)) |
… |
… |
|
157 | 158 | try: |
158 | 159 | # This file has a file path that we can move. |
159 | 160 | 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) |
161 | 162 | content.close() |
162 | 163 | |
163 | 164 | # This is a normal uploadedfile that we can stream. |
… |
… |
|
166 | 167 | # OSError if the file already exists before we open it. |
167 | 168 | fd = os.open(full_path, os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, 'O_BINARY', 0)) |
168 | 169 | try: |
169 | | locks.lock(fd, locks.LOCK_EX) |
| 170 | self.locks.lock(fd, self.locks.LOCK_EX) |
170 | 171 | for chunk in content.chunks(): |
171 | 172 | os.write(fd, chunk) |
172 | 173 | finally: |
173 | | locks.unlock(fd) |
| 174 | self.locks.unlock(fd) |
174 | 175 | os.close(fd) |
175 | 176 | except OSError, e: |
176 | 177 | if e.errno == errno.EEXIST: |