@@ -28,14 +28,14 @@ use uv_git::{GIT_LFS, GitError};
2828use uv_install_wheel:: validate_and_heal_record;
2929use uv_platform_tags:: Tags ;
3030use uv_pypi_types:: { HashDigest , HashDigests , PyProjectToml } ;
31+ use uv_python:: PythonVariant ;
3132use uv_redacted:: DisplaySafeUrl ;
3233use uv_types:: { BuildContext , BuildStack } ;
3334use uv_warnings:: warn_user_once;
3435
3536use crate :: archive:: Archive ;
36- use uv_python:: PythonVariant ;
37-
3837use crate :: error:: PythonVersion ;
38+ use crate :: hash:: http_hash_algorithms;
3939use crate :: metadata:: { ArchiveMetadata , Metadata } ;
4040use crate :: source:: SourceDistributionBuilder ;
4141use crate :: { Error , LocalWheel , Reporter , RequiresDist } ;
@@ -731,7 +731,7 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
731731 . into_async_read ( ) ;
732732
733733 // Create a hasher for each hash algorithm.
734- let algorithms = hashes . algorithms ( ) ;
734+ let algorithms = http_hash_algorithms ( hashes ) ;
735735 let mut hashers = algorithms. into_iter ( ) . map ( Hasher :: from) . collect :: < Vec < _ > > ( ) ;
736736 let mut hasher = uv_extract:: hash:: HashReader :: new ( reader. compat ( ) , & mut hashers) ;
737737
@@ -768,10 +768,8 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
768768 }
769769 } ,
770770 } ;
771- // If necessary, exhaust the reader to compute the hash.
772- if !hashes. is_none ( ) {
773- hasher. finish ( ) . await . map_err ( Error :: HashExhaustion ) ?;
774- }
771+ // Exhaust the reader to compute the hashes.
772+ hasher. finish ( ) . await . map_err ( Error :: HashExhaustion ) ?;
775773
776774 // Before we make the wheel accessible by persisting it, ensure that the RECORD is
777775 // valid.
@@ -891,8 +889,6 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
891889 // Create an entry for the HTTP cache.
892890 let http_entry = wheel_entry. with_file ( format ! ( "{}.http" , filename. cache_key( ) ) ) ;
893891
894- let query_url = & url. clone ( ) ;
895-
896892 let download = |response : reqwest:: Response | {
897893 async {
898894 let size = size. or_else ( || content_length ( & response) ) ;
@@ -906,6 +902,9 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
906902 . bytes_stream ( )
907903 . map_err ( |err| self . handle_response_errors ( err) )
908904 . into_async_read ( ) ;
905+ let algorithms = http_hash_algorithms ( hashes) ;
906+ let mut hashers = algorithms. into_iter ( ) . map ( Hasher :: from) . collect :: < Vec < _ > > ( ) ;
907+ let mut hasher = uv_extract:: hash:: HashReader :: new ( reader. compat ( ) , & mut hashers) ;
909908
910909 // Download the wheel to a temporary file.
911910 let temp_file = tempfile:: tempfile_in ( self . build_context . cache ( ) . root ( ) )
@@ -917,18 +916,16 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
917916
918917 match progress {
919918 Some ( ( reporter, progress) ) => {
920- // Wrap the reader in a progress reporter. This will report 100% progress
921- // after the download is complete, even if we still have to unzip and hash
922- // part of the file.
923- let mut reader =
924- ProgressReader :: new ( reader. compat ( ) , progress, & * * reporter) ;
919+ // Wrap the reader in a progress reporter. This will report 100% progress once
920+ // the download is complete, before the wheel is unzipped.
921+ let mut reader = ProgressReader :: new ( & mut hasher, progress, & * * reporter) ;
925922
926923 tokio:: io:: copy ( & mut reader, & mut writer)
927924 . await
928925 . map_err ( Error :: CacheWrite ) ?;
929926 }
930927 None => {
931- tokio:: io:: copy ( & mut reader . compat ( ) , & mut writer)
928+ tokio:: io:: copy ( & mut hasher , & mut writer)
932929 . await
933930 . map_err ( Error :: CacheWrite ) ?;
934931 }
@@ -942,47 +939,17 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
942939 . await
943940 . map_err ( Error :: CacheWrite ) ?;
944941
945- // If no hashes are required, extract the wheel without hashing.
946- let ( files, hashes) = if hashes. is_none ( ) {
947- let target = temp_dir. path ( ) . to_owned ( ) ;
948- let files = match extension {
949- WheelExtension :: Whl => {
950- let file = file. into_std ( ) . await ;
951- tokio:: task:: spawn_blocking ( move || uv_extract:: unzip ( file, & target) )
952- . await ?
953- }
954- WheelExtension :: WhlZst => {
955- uv_extract:: stream:: untar_zst ( file, & target) . await
956- }
942+ let target = temp_dir. path ( ) . to_owned ( ) ;
943+ let files = match extension {
944+ WheelExtension :: Whl => {
945+ let file = file. into_std ( ) . await ;
946+ tokio:: task:: spawn_blocking ( move || uv_extract:: unzip ( file, & target) )
947+ . await ?
957948 }
958- . map_err ( |err| Error :: Extract ( filename. to_string ( ) , err) ) ?;
959-
960- ( files, HashDigests :: empty ( ) )
961- } else {
962- // Create a hasher for each hash algorithm.
963- let algorithms = hashes. algorithms ( ) ;
964- let mut hashers = algorithms. into_iter ( ) . map ( Hasher :: from) . collect :: < Vec < _ > > ( ) ;
965- let mut hasher = uv_extract:: hash:: HashReader :: new ( file, & mut hashers) ;
966-
967- let files = match extension {
968- WheelExtension :: Whl => {
969- uv_extract:: stream:: unzip ( query_url, & mut hasher, temp_dir. path ( ) )
970- . await
971- . map_err ( |err| Error :: Extract ( filename. to_string ( ) , err) ) ?
972- }
973- WheelExtension :: WhlZst => {
974- uv_extract:: stream:: untar_zst ( & mut hasher, temp_dir. path ( ) )
975- . await
976- . map_err ( |err| Error :: Extract ( filename. to_string ( ) , err) ) ?
977- }
978- } ;
979-
980- // If necessary, exhaust the reader to compute the hash.
981- hasher. finish ( ) . await . map_err ( Error :: HashExhaustion ) ?;
982- let hashes = hashers. into_iter ( ) . map ( HashDigest :: from) . collect ( ) ;
983-
984- ( files, hashes)
985- } ;
949+ WheelExtension :: WhlZst => uv_extract:: stream:: untar_zst ( file, & target) . await ,
950+ }
951+ . map_err ( |err| Error :: Extract ( filename. to_string ( ) , err) ) ?;
952+ let hashes = hashers. into_iter ( ) . map ( HashDigest :: from) . collect ( ) ;
986953
987954 // Before we make the wheel accessible by persisting it, ensure that the RECORD is
988955 // valid.
0 commit comments