1+ use std:: borrow:: Borrow ;
12use std:: io:: BufWriter ;
23
34use anyhow:: Result ;
@@ -8,7 +9,7 @@ use symbolic::debuginfo::sourcebundle::{
89} ;
910use url:: Url ;
1011
11- use crate :: utils:: file_upload:: { SourceFiles , UploadContext } ;
12+ use crate :: utils:: file_upload:: { SourceFile , UploadContext } ;
1213use crate :: utils:: fs:: TempFile ;
1314use crate :: utils:: non_empty:: NonEmptySlice ;
1415use crate :: utils:: progress:: ProgressBar ;
@@ -38,11 +39,15 @@ impl<'a> From<&'a UploadContext<'a>> for BundleContext<'a> {
3839/// from the upload context.
3940///
4041/// Returns a `TempFile` containing the source bundle.
41- pub fn build < ' a , C > ( context : C , files : & SourceFiles , debug_id : Option < DebugId > ) -> Result < TempFile >
42+ pub fn build < ' a , C , F , S > ( context : C , files : F , debug_id : Option < DebugId > ) -> Result < TempFile >
4243where
4344 C : Into < BundleContext < ' a > > ,
45+ F : IntoIterator < Item = S > ,
46+ S : Borrow < SourceFile > ,
4447{
4548 let context = context. into ( ) ;
49+ let files = files. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
50+
4651 let progress_style = ProgressStyle :: default_bar ( ) . template (
4752 "{prefix:.dim} Bundling files for upload... {msg:.dim}\
4853 \n {wide_bar} {pos}/{len}",
5661 let mut bundle = SourceBundleWriter :: start ( BufWriter :: new ( archive. open ( ) ?) ) ?;
5762
5863 // source bundles get a random UUID as debug id
59- let debug_id = debug_id. unwrap_or_else ( || build_debug_id ( files) ) ;
64+ let debug_id = debug_id. unwrap_or_else ( || build_debug_id ( & files) ) ;
6065 bundle. set_attribute ( "debug_id" , debug_id. to_string ( ) ) ;
6166
6267 if let Some ( note) = context. note {
7782
7883 let mut bundle_file_count = 0 ;
7984
80- for file in files. values ( ) {
85+ for file in files. iter ( ) . map ( Borrow :: borrow ) {
8186 pb. inc ( 1 ) ;
8287 pb. set_message ( & file. url ) ;
8388
@@ -128,9 +133,12 @@ where
128133
129134/// Creates a debug id from a map of source files by hashing each file's
130135/// URL, contents, type, and headers.
131- fn build_debug_id ( files : & SourceFiles ) -> DebugId {
136+ fn build_debug_id < S > ( files : & [ S ] ) -> DebugId
137+ where
138+ S : Borrow < SourceFile > ,
139+ {
132140 let mut hash = sha1_smol:: Sha1 :: new ( ) ;
133- for source_file in files. values ( ) {
141+ for source_file in files. iter ( ) . map ( Borrow :: borrow ) {
134142 hash. update ( source_file. url . as_bytes ( ) ) ;
135143 hash. update ( & source_file. contents ) ;
136144 hash. update ( format ! ( "{:?}" , source_file. ty) . as_bytes ( ) ) ;
@@ -216,21 +224,18 @@ mod tests {
216224
217225 let source_files = [ "bundle.min.js.map" , "vendor.min.js.map" ]
218226 . into_iter ( )
219- . map ( |name| {
220- let file = SourceFile {
221- url : format ! ( "~/{name}" ) ,
222- path : format ! ( "tests/integration/_fixtures/{name}" ) . into ( ) ,
223- contents : std:: fs:: read ( format ! ( "tests/integration/_fixtures/{name}" ) )
224- . unwrap ( )
225- . into ( ) ,
226- ty : SourceFileType :: SourceMap ,
227- headers : Default :: default ( ) ,
228- messages : Default :: default ( ) ,
229- already_uploaded : false ,
230- } ;
231- ( format ! ( "~/{name}" ) , file)
227+ . map ( |name| SourceFile {
228+ url : format ! ( "~/{name}" ) ,
229+ path : format ! ( "tests/integration/_fixtures/{name}" ) . into ( ) ,
230+ contents : std:: fs:: read ( format ! ( "tests/integration/_fixtures/{name}" ) )
231+ . unwrap ( )
232+ . into ( ) ,
233+ ty : SourceFileType :: SourceMap ,
234+ headers : Default :: default ( ) ,
235+ messages : Default :: default ( ) ,
236+ already_uploaded : false ,
232237 } )
233- . collect ( ) ;
238+ . collect :: < Vec < _ > > ( ) ;
234239
235240 let file = build ( context, & source_files, None ) . unwrap ( ) ;
236241
0 commit comments