@@ -412,7 +412,6 @@ def _download_file(self, url, local_filepath, timeout=None, auth=None,
412
412
verbose : bool
413
413
Whether to show download progress. Defaults to True.
414
414
"""
415
-
416
415
if head_safe :
417
416
response = self ._session .request ("HEAD" , url ,
418
417
timeout = timeout , stream = True ,
@@ -442,6 +441,7 @@ def _download_file(self, url, local_filepath, timeout=None, auth=None,
442
441
.format (local_filepath , existing_file_length ))
443
442
return
444
443
elif existing_file_length == 0 :
444
+ log .info (f"Found existing { local_filepath } file with length 0. Overwriting." )
445
445
open_mode = 'wb'
446
446
if head_safe :
447
447
response = self ._session .request (method , url ,
@@ -459,6 +459,7 @@ def _download_file(self, url, local_filepath, timeout=None, auth=None,
459
459
end = "{0}" .format (length - 1 ) if length is not None else ""
460
460
self ._session .headers ['Range' ] = "bytes={0}-{1}" .format (existing_file_length ,
461
461
end )
462
+ log .debug (f"Continuing with range={ self ._session .headers ['Range' ]} " )
462
463
463
464
response = self ._session .request (method , url ,
464
465
timeout = timeout , stream = True ,
@@ -471,8 +472,16 @@ def _download_file(self, url, local_filepath, timeout=None, auth=None,
471
472
statinfo = os .stat (local_filepath )
472
473
if statinfo .st_size != length :
473
474
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." )
475
480
open_mode = 'wb'
481
+ response = self ._session .request (method , url ,
482
+ timeout = timeout , stream = True ,
483
+ auth = auth , ** kwargs )
484
+ response .raise_for_status ()
476
485
else :
477
486
log .info ("Found cached file {0} with expected size {1}."
478
487
.format (local_filepath , statinfo .st_size ))
@@ -493,7 +502,7 @@ def _download_file(self, url, local_filepath, timeout=None, auth=None,
493
502
blocksize = astropy .utils .data .conf .download_block_size
494
503
495
504
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 } " )
497
506
498
507
bytes_read = 0
499
508
0 commit comments