21
21
import concurrent .futures
22
22
import dataclasses
23
23
import functools
24
- import hashlib
25
24
import typing
26
25
from typing import Any
27
26
import uuid
@@ -316,8 +315,8 @@ def downloaded_size(self):
316
315
"""Returns the total size of downloaded files."""
317
316
return sum (url_info .size for url_info in self ._recorded_url_infos .values ())
318
317
319
- def _get_dl_path (self , url : str , sha256 : str ) -> epath .Path :
320
- return self ._download_dir / resource_lib .get_dl_fname (url , sha256 )
318
+ def _get_dl_path (self , url : str , checksum : str | None = None ) -> epath .Path :
319
+ return self ._download_dir / resource_lib .get_dl_fname (url , checksum )
321
320
322
321
@property
323
322
def register_checksums (self ):
@@ -368,11 +367,9 @@ def _download(self, resource: Url) -> promise.Promise[epath.Path]:
368
367
manual_dir = self ._manual_dir ,
369
368
expected_url_info = expected_url_info ,
370
369
)
371
- url_path = self ._get_dl_path (
372
- url , sha256 = hashlib .sha256 (url .encode ('utf-8' )).hexdigest ()
373
- )
370
+ url_path = self ._get_dl_path (url )
374
371
checksum_path = (
375
- self ._get_dl_path (url , sha256 = expected_url_info .checksum )
372
+ self ._get_dl_path (url , expected_url_info .checksum )
376
373
if expected_url_info
377
374
else None
378
375
)
@@ -392,10 +389,11 @@ def _download(self, resource: Url) -> promise.Promise[epath.Path]:
392
389
self ._downloader .increase_tqdm (dl_result )
393
390
future = promise .Promise .resolve (dl_result )
394
391
else :
395
- # Download in an empty tmp directory (to avoid name collisions)
392
+ # Download in a tmp directory next to url_path (to avoid name collisions)
396
393
# `download_tmp_dir` is cleaned-up in `_rename_and_get_final_dl_path`
397
- dirname = f'{ resource_lib .get_dl_dirname (url )} .tmp.{ uuid .uuid4 ().hex } '
398
- download_tmp_dir = self ._download_dir / dirname
394
+ download_tmp_dir = (
395
+ url_path .parent / f'{ url_path .name } .tmp.{ uuid .uuid4 ().hex } '
396
+ )
399
397
download_tmp_dir .mkdir ()
400
398
logging .info (f'Downloading { url } into { download_tmp_dir } ...' )
401
399
future = self ._downloader .download (
0 commit comments