@@ -179,7 +179,10 @@ def unpack_url(
179
179
180
180
181
181
def _check_download_dir (
182
- link : Link , download_dir : str , hashes : Optional [Hashes ]
182
+ link : Link ,
183
+ download_dir : str ,
184
+ hashes : Optional [Hashes ],
185
+ warn_on_hash_mismatch : bool = True ,
183
186
) -> Optional [str ]:
184
187
"""Check download_dir for previously downloaded file with correct hash
185
188
If a correct file is found return its path else None
@@ -195,10 +198,11 @@ def _check_download_dir(
195
198
try :
196
199
hashes .check_against_path (download_path )
197
200
except HashMismatch :
198
- logger .warning (
199
- "Previously-downloaded file %s has bad hash. Re-downloading." ,
200
- download_path ,
201
- )
201
+ if warn_on_hash_mismatch :
202
+ logger .warning (
203
+ "Previously-downloaded file %s has bad hash. Re-downloading." ,
204
+ download_path ,
205
+ )
202
206
os .unlink (download_path )
203
207
return None
204
208
return download_path
@@ -485,7 +489,18 @@ def prepare_linked_requirement(
485
489
file_path = None
486
490
if self .download_dir is not None and req .link .is_wheel :
487
491
hashes = self ._get_linked_req_hashes (req )
488
- file_path = _check_download_dir (req .link , self .download_dir , hashes )
492
+ file_path = _check_download_dir (
493
+ req .link ,
494
+ self .download_dir ,
495
+ hashes ,
496
+ # When a locally built wheel has been found in cache, we don't warn
497
+ # about re-downloading when the already downloaded wheel hash does
498
+ # not match. This is because the hash must be checked against the
499
+ # original link, not the cached link. It that case the already
500
+ # downloaded file will be removed and re-fetched from cache (which
501
+ # implies a hash check against the cache entry's origin.json).
502
+ warn_on_hash_mismatch = not req .original_link_is_in_wheel_cache ,
503
+ )
489
504
490
505
if file_path is not None :
491
506
# The file is already available, so mark it as downloaded
0 commit comments