Skip to content

Commit 0c10fe9

Browse files
committed
fix @eas342's bug - which was that, if a partial file was detected and
continuation was set to False (which is the case - MAST hard-codes that), no download was being done - we were only retrieving the header, not the data
1 parent 9571482 commit 0c10fe9

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

astroquery/query.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ def _download_file(self, url, local_filepath, timeout=None, auth=None,
412412
verbose : bool
413413
Whether to show download progress. Defaults to True.
414414
"""
415-
416415
if head_safe:
417416
response = self._session.request("HEAD", url,
418417
timeout=timeout, stream=True,
@@ -442,6 +441,7 @@ def _download_file(self, url, local_filepath, timeout=None, auth=None,
442441
.format(local_filepath, existing_file_length))
443442
return
444443
elif existing_file_length == 0:
444+
log.info(f"Found existing {local_filepath} file with length 0. Overwriting.")
445445
open_mode = 'wb'
446446
if head_safe:
447447
response = self._session.request(method, url,
@@ -459,6 +459,7 @@ def _download_file(self, url, local_filepath, timeout=None, auth=None,
459459
end = "{0}".format(length-1) if length is not None else ""
460460
self._session.headers['Range'] = "bytes={0}-{1}".format(existing_file_length,
461461
end)
462+
log.debug(f"Continuing with range={self._session.headers['Range']}")
462463

463464
response = self._session.request(method, url,
464465
timeout=timeout, stream=True,
@@ -471,8 +472,16 @@ def _download_file(self, url, local_filepath, timeout=None, auth=None,
471472
statinfo = os.stat(local_filepath)
472473
if statinfo.st_size != length:
473474
log.warning(f"Found cached file {local_filepath} with size {statinfo.st_size} "
474-
f"that is different from expected size {length}")
475+
f"that is different from expected size {length}. ")
476+
if continuation:
477+
log.warning(
478+
"Continuation was requested but is not possible because "
479+
"'Accepts-Ranges' is not in the response headers.")
475480
open_mode = 'wb'
481+
response = self._session.request(method, url,
482+
timeout=timeout, stream=True,
483+
auth=auth, **kwargs)
484+
response.raise_for_status()
476485
else:
477486
log.info("Found cached file {0} with expected size {1}."
478487
.format(local_filepath, statinfo.st_size))
@@ -493,7 +502,7 @@ def _download_file(self, url, local_filepath, timeout=None, auth=None,
493502
blocksize = astropy.utils.data.conf.download_block_size
494503

495504
log.debug(f"Downloading URL {url} to {local_filepath} with size {length} "
496-
f"by blocks of {blocksize}")
505+
f"by blocks of {blocksize} with open_mode={open_mode}")
497506

498507
bytes_read = 0
499508

0 commit comments

Comments
 (0)