|
14 | 14 |
|
15 | 15 | from django.conf import settings
|
16 | 16 | from django.core.exceptions import SuspiciousFileOperation
|
17 |
| -from django.core.files.storage import get_storage_class, FileSystemStorage |
| 17 | +from django.core.files.storage import get_storage_class |
18 | 18 |
|
19 | 19 | from readthedocs.core.utils import safe_makedirs
|
20 | 20 | from readthedocs.core.utils.extend import SettingsOverrideObject
|
@@ -205,27 +205,23 @@ def get_storage_path(cls, path):
|
205 | 205 | def copy(cls, path, target, host, is_file=False, **kwargs): # pylint: disable=arguments-differ
|
206 | 206 | RemotePuller.copy(path, target, host, is_file, **kwargs)
|
207 | 207 |
|
208 |
| - if isinstance(storage, FileSystemStorage): |
| 208 | + if getattr(storage, 'write_build_media', False): |
209 | 209 | # This is a sanity check for the case where
|
210 | 210 | # storage is backed by the local filesystem
|
211 | 211 | # In that case, removing the original target file locally
|
212 | 212 | # would remove the file from storage as well
|
213 |
| - return |
214 | 213 |
|
215 |
| - if is_file and os.path.exists(target) and \ |
216 |
| - any([target.lower().endswith(ext) for ext in cls.extensions]): |
217 |
| - log.info("Selective Copy %s to media storage", target) |
| 214 | + if is_file and os.path.exists(target) and \ |
| 215 | + any([target.lower().endswith(ext) for ext in cls.extensions]): |
| 216 | + log.info("Selective Copy %s to media storage", target) |
218 | 217 |
|
219 |
| - storage_path = cls.get_storage_path(target) |
| 218 | + storage_path = cls.get_storage_path(target) |
220 | 219 |
|
221 |
| - if storage.exists(storage_path): |
222 |
| - storage.delete(storage_path) |
| 220 | + if storage.exists(storage_path): |
| 221 | + storage.delete(storage_path) |
223 | 222 |
|
224 |
| - with open(target, 'rb') as fd: |
225 |
| - storage.save(storage_path, fd) |
226 |
| - |
227 |
| - # remove the original after copying |
228 |
| - os.remove(target) |
| 223 | + with open(target, 'rb') as fd: |
| 224 | + storage.save(storage_path, fd) |
229 | 225 |
|
230 | 226 |
|
231 | 227 | class Syncer(SettingsOverrideObject):
|
|
0 commit comments