@@ -40,7 +40,7 @@ use uv_types::{BuildContext, BuildStack};
4040
4141use crate :: archive:: Archive ;
4242use crate :: error:: PythonVersion ;
43- use crate :: extracted_wheel:: { ExtractedWheel , HashedWheel } ;
43+ use crate :: extracted_wheel:: { ExtractedWheel , HashedWheel , WheelExtractor } ;
4444use crate :: hash:: http_hash_algorithms;
4545use crate :: metadata:: { ArchiveMetadata , Metadata } ;
4646use crate :: source:: SourceDistributionBuilder ;
@@ -716,27 +716,24 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
716716 let mut hasher = uv_extract:: hash:: HashReader :: new ( reader. compat ( ) , & mut hashers) ;
717717
718718 // Download and unzip the wheel to a temporary directory.
719- let temp_dir = tempfile:: tempdir_in ( self . build_context . cache ( ) . root ( ) )
720- . map_err ( Error :: CacheWrite ) ?;
719+ let extractor = WheelExtractor :: new (
720+ self . build_context . cache ( ) . root ( ) ,
721+ self . content_addressed_cache ,
722+ )
723+ . map_err ( Error :: CacheWrite ) ?;
721724
722- let ( temp_dir , mut extracted) = match progress {
725+ let mut extracted = match progress {
723726 Some ( ( reporter, progress) ) => {
724727 let mut reader = ProgressReader :: new ( & mut hasher, progress, & * * reporter) ;
725- ExtractedWheel :: extract_streaming (
726- & mut reader,
727- temp_dir,
728- self . content_addressed_cache ,
729- )
730- . await
731- . map_err ( |err| Error :: Extract ( filename. to_string ( ) , err) ) ?
728+ extractor
729+ . extract_streaming ( & mut reader)
730+ . await
731+ . map_err ( |err| Error :: Extract ( filename. to_string ( ) , err) ) ?
732732 }
733- None => ExtractedWheel :: extract_streaming (
734- & mut hasher,
735- temp_dir,
736- self . content_addressed_cache ,
737- )
738- . await
739- . map_err ( |err| Error :: Extract ( filename. to_string ( ) , err) ) ?,
733+ None => extractor
734+ . extract_streaming ( & mut hasher)
735+ . await
736+ . map_err ( |err| Error :: Extract ( filename. to_string ( ) , err) ) ?,
740737 } ;
741738 // Exhaust the reader to compute the hashes.
742739 hasher. finish ( ) . await . map_err ( Error :: HashExhaustion ) ?;
@@ -753,11 +750,11 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
753750
754751 // Before we make the wheel accessible by persisting it, ensure that the RECORD is
755752 // valid.
756- extracted. validate_and_heal_record ( temp_dir . path ( ) , dist) ?;
753+ extracted. validate_and_heal_record ( dist) ?;
757754
758755 // Persist the temporary directory to the directory store.
759756 let id = self
760- . persist_extracted_wheel ( temp_dir , wheel_entry. path ( ) , extracted . into_hashed ( ) )
757+ . persist_extracted_wheel ( extracted , wheel_entry. path ( ) )
761758 . await ?;
762759
763760 if let Some ( ( reporter, progress) ) = progress {
@@ -936,29 +933,28 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
936933 let actual_size = hasher. bytes_read ( ) ;
937934
938935 // Unzip the wheel to a temporary directory.
939- let temp_dir = tempfile:: tempdir_in ( self . build_context . cache ( ) . root ( ) )
940- . map_err ( Error :: CacheWrite ) ?;
936+ let extractor =
937+ WheelExtractor :: new ( self . build_context . cache ( ) . root ( ) , content_addressed_cache)
938+ . map_err ( Error :: CacheWrite ) ?;
941939 let mut file = writer. into_inner ( ) ;
942940 file. seek ( io:: SeekFrom :: Start ( 0 ) )
943941 . await
944942 . map_err ( Error :: CacheWrite ) ?;
945943
946- let target = temp_dir. path ( ) . to_owned ( ) ;
947944 let file = file. into_std ( ) . await ;
948- let mut extracted = tokio:: task:: spawn_blocking ( move || {
949- ExtractedWheel :: extract_seekable ( file, & target, content_addressed_cache)
950- } )
951- . await ?
952- . map_err ( |err| Error :: Extract ( filename. to_string ( ) , err) ) ?;
945+ let mut extracted =
946+ tokio:: task:: spawn_blocking ( move || extractor. extract_seekable ( file) )
947+ . await ?
948+ . map_err ( |err| Error :: Extract ( filename. to_string ( ) , err) ) ?;
953949 let hashes = hashers. into_iter ( ) . map ( HashDigest :: from) . collect ( ) ;
954950
955951 // Before we make the wheel accessible by persisting it, ensure that the RECORD is
956952 // valid.
957- extracted. validate_and_heal_record ( temp_dir . path ( ) , dist) ?;
953+ extracted. validate_and_heal_record ( dist) ?;
958954
959955 // Persist the temporary directory to the directory store.
960956 let id = self
961- . persist_extracted_wheel ( temp_dir , wheel_entry. path ( ) , extracted . into_hashed ( ) )
957+ . persist_extracted_wheel ( extracted , wheel_entry. path ( ) )
962958 . await ?;
963959
964960 if let Some ( ( reporter, progress) ) = progress {
@@ -1128,22 +1124,22 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
11281124 let file = fs_err:: tokio:: File :: open ( path)
11291125 . await
11301126 . map_err ( Error :: CacheRead ) ?;
1131- let temp_dir = tempfile:: tempdir_in ( self . build_context . cache ( ) . root ( ) )
1132- . map_err ( Error :: CacheWrite ) ?;
1127+ let extractor = WheelExtractor :: new (
1128+ self . build_context . cache ( ) . root ( ) ,
1129+ self . content_addressed_cache ,
1130+ )
1131+ . map_err ( Error :: CacheWrite ) ?;
11331132
11341133 // Create a hasher for each hash algorithm.
11351134 let algorithms = hashes. algorithms ( ) ;
11361135 let mut hashers = algorithms. into_iter ( ) . map ( Hasher :: from) . collect :: < Vec < _ > > ( ) ;
11371136 let mut hasher = uv_extract:: hash:: HashReader :: new ( file, & mut hashers) ;
11381137
11391138 // Unzip the wheel to a temporary directory.
1140- let ( temp_dir, mut extracted) = ExtractedWheel :: extract_streaming (
1141- & mut hasher,
1142- temp_dir,
1143- self . content_addressed_cache ,
1144- )
1145- . await
1146- . map_err ( |err| Error :: Extract ( filename. to_string ( ) , err) ) ?;
1139+ let mut extracted = extractor
1140+ . extract_streaming ( & mut hasher)
1141+ . await
1142+ . map_err ( |err| Error :: Extract ( filename. to_string ( ) , err) ) ?;
11471143
11481144 // Exhaust the reader to compute the hash.
11491145 hasher. finish ( ) . await . map_err ( Error :: HashExhaustion ) ?;
@@ -1152,11 +1148,11 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
11521148
11531149 // Before we make the wheel accessible by persisting it, ensure that the RECORD is
11541150 // valid.
1155- extracted. validate_and_heal_record ( temp_dir . path ( ) , dist) ?;
1151+ extracted. validate_and_heal_record ( dist) ?;
11561152
11571153 // Persist the temporary directory to the directory store.
11581154 let id = self
1159- . persist_extracted_wheel ( temp_dir , wheel_entry. path ( ) , extracted . into_hashed ( ) )
1155+ . persist_extracted_wheel ( extracted , wheel_entry. path ( ) )
11601156 . await ?;
11611157
11621158 // Create an archive.
@@ -1193,31 +1189,26 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
11931189 ) -> Result < ArchiveId , Error > {
11941190 let content_addressed_cache = self . content_addressed_cache ;
11951191
1196- let ( temp_dir , mut extracted) = tokio:: task:: spawn_blocking ( {
1192+ let mut extracted = tokio:: task:: spawn_blocking ( {
11971193 let path = path. to_owned ( ) ;
11981194 let root = self . build_context . cache ( ) . root ( ) . to_path_buf ( ) ;
11991195 move || -> Result < _ , Error > {
12001196 // Unzip the wheel into a temporary directory.
1201- let temp_dir = tempfile:: tempdir_in ( root) . map_err ( Error :: CacheWrite ) ?;
1197+ let extractor = WheelExtractor :: new ( & root, content_addressed_cache)
1198+ . map_err ( Error :: CacheWrite ) ?;
12021199 let reader = fs_err:: File :: open ( & path) . map_err ( Error :: CacheWrite ) ?;
1203- let extracted = ExtractedWheel :: extract_seekable (
1204- reader,
1205- temp_dir. path ( ) ,
1206- content_addressed_cache,
1207- )
1208- . map_err ( |err| Error :: Extract ( path. to_string_lossy ( ) . into_owned ( ) , err) ) ?;
1209- Ok ( ( temp_dir, extracted) )
1200+ extractor
1201+ . extract_seekable ( reader)
1202+ . map_err ( |err| Error :: Extract ( path. to_string_lossy ( ) . into_owned ( ) , err) )
12101203 }
12111204 } )
12121205 . await ??;
12131206
12141207 // Before we make the wheel accessible by persisting it, ensure that the RECORD is valid.
1215- extracted. validate_and_heal_record ( temp_dir . path ( ) , dist) ?;
1208+ extracted. validate_and_heal_record ( dist) ?;
12161209
12171210 // Persist the temporary directory to the directory store.
1218- let id = self
1219- . persist_extracted_wheel ( temp_dir, target, extracted. into_hashed ( ) )
1220- . await ?;
1211+ let id = self . persist_extracted_wheel ( extracted, target) . await ?;
12211212
12221213 Ok ( id)
12231214 }
@@ -1228,10 +1219,10 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
12281219 /// persistence retains the existing behavior of assigning a unique archive ID.
12291220 async fn persist_extracted_wheel (
12301221 & self ,
1231- temp_dir : tempfile :: TempDir ,
1222+ extracted : ExtractedWheel ,
12321223 target : & Path ,
1233- hashed_wheel : Option < HashedWheel > ,
12341224 ) -> Result < ArchiveId , Error > {
1225+ let ( temp_dir, hashed_wheel) = extracted. into_parts ( ) ;
12351226 let cache = self . build_context . cache ( ) ;
12361227 let ( temp_dir, id) = if let Some ( HashedWheel { files, tree } ) = hashed_wheel {
12371228 let digest = DirectoryDigest :: from ( tree. hash ( ) ) ;
0 commit comments