Skip to content

Commit 03787f4

Browse files
committed
Improved filesystem storage check
- Basically we need to explicitly tell the storage to sync build media
1 parent 6edacad commit 03787f4

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

readthedocs/builds/syncers.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from django.conf import settings
1616
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
1818

1919
from readthedocs.core.utils import safe_makedirs
2020
from readthedocs.core.utils.extend import SettingsOverrideObject
@@ -205,27 +205,23 @@ def get_storage_path(cls, path):
205205
def copy(cls, path, target, host, is_file=False, **kwargs): # pylint: disable=arguments-differ
206206
RemotePuller.copy(path, target, host, is_file, **kwargs)
207207

208-
if isinstance(storage, FileSystemStorage):
208+
if getattr(storage, 'write_build_media', False):
209209
# This is a sanity check for the case where
210210
# storage is backed by the local filesystem
211211
# In that case, removing the original target file locally
212212
# would remove the file from storage as well
213-
return
214213

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)
218217

219-
storage_path = cls.get_storage_path(target)
218+
storage_path = cls.get_storage_path(target)
220219

221-
if storage.exists(storage_path):
222-
storage.delete(storage_path)
220+
if storage.exists(storage_path):
221+
storage.delete(storage_path)
223222

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)
229225

230226

231227
class Syncer(SettingsOverrideObject):

readthedocs/projects/tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import requests
2121
from celery.exceptions import SoftTimeLimitExceeded
2222
from django.conf import settings
23-
from django.core.files.storage import get_storage_class, FileSystemStorage
23+
from django.core.files.storage import get_storage_class
2424
from django.db.models import Q
2525
from django.urls import reverse
2626
from django.utils import timezone
@@ -727,7 +727,7 @@ def update_app_instances(
727727
)
728728
hostname = socket.gethostname()
729729

730-
if not isinstance(storage, FileSystemStorage):
730+
if getattr(storage, 'write_build_media', False):
731731
# Handle the case where we want to upload some built assets to our storage
732732
move_files.delay(
733733
self.version.pk,

0 commit comments

Comments
 (0)