@@ -20,6 +20,7 @@ use tsify_next::Tsify;
2020use wasm_bindgen:: prelude:: * ;
2121
2222use crate :: bundle_meta:: { BundleMeta , VersionedBundle } ;
23+ use crate :: files:: FileSetType ;
2324
2425/// Utility type for packing files into tarball.
2526///
@@ -68,10 +69,16 @@ impl<'a> BundlerUtil<'a> {
6869 }
6970
7071 // Add all files to the tarball.
72+ // Skip Internal file_sets if internal_bundled_file is set, to avoid adding the same file twice.
73+ // If internal_bundled_file is None, we still add Internal file_sets as a fallback.
74+ let has_internal_bundled_file = self . meta . internal_bundled_file . is_some ( ) ;
7175 self . meta
7276 . base_props
7377 . file_sets
7478 . iter ( )
79+ . filter ( |file_set| {
80+ !has_internal_bundled_file || file_set. file_set_type != FileSetType :: Internal
81+ } )
7582 . try_for_each ( |file_set| {
7683 file_set. files . iter ( ) . try_for_each ( |bundled_file| {
7784 let path = std:: path:: Path :: new ( & bundled_file. original_path ) ;
@@ -296,14 +303,14 @@ mod tests {
296303 use tempfile:: tempdir;
297304
298305 use super :: * ;
299- use crate :: files:: { FileSet , FileSetType } ;
300306 use crate :: Test ;
307+ use crate :: files:: { FileSet , FileSetType } ;
301308 use crate :: {
309+ BundledFile ,
302310 bundle_meta:: {
303311 BundleMeta , BundleMetaBaseProps , BundleMetaDebugProps , BundleMetaJunitProps ,
304312 META_VERSION ,
305313 } ,
306- BundledFile ,
307314 } ;
308315
309316 fn create_bundle_meta ( bundled_file : Option < BundledFile > ) -> BundleMeta {
@@ -450,4 +457,98 @@ mod tests {
450457 assert_eq ! ( parsed_meta. internal_bundled_file( ) , bundled_file) ;
451458 assert_eq ! ( internal_bin, test_report) ;
452459 }
460+
461+ #[ test]
462+ pub fn test_no_duplicate_internal_file ( ) {
463+ let temp_dir = tempdir ( ) . unwrap ( ) ;
464+ let internal_path = "internal/0" . to_string ( ) ;
465+ let full_bin_path = temp_dir. path ( ) . join ( "test_internal.bin" ) ;
466+
467+ let test_report = TestReport {
468+ test_results : Vec :: new ( ) ,
469+ uploader_metadata : Some ( UploaderMetadata {
470+ version : "v1" . to_string ( ) ,
471+ origin : "A test" . to_string ( ) ,
472+ upload_time : None ,
473+ variant : "A variant" . to_string ( ) ,
474+ } ) ,
475+ } ;
476+ let mut buf = Vec :: new ( ) ;
477+ prost:: Message :: encode ( & test_report, & mut buf) . unwrap ( ) ;
478+ std:: fs:: write ( & full_bin_path, buf) . unwrap ( ) ;
479+
480+ let bundled_file = BundledFile {
481+ original_path : full_bin_path. to_str ( ) . unwrap ( ) . to_string ( ) ,
482+ original_path_rel : None ,
483+ path : internal_path. clone ( ) ,
484+ ..Default :: default ( )
485+ } ;
486+
487+ let mut repo = BundleRepo :: default ( ) ;
488+ repo. repo . owner = "org" . to_string ( ) ;
489+ repo. repo . name = "repo" . to_string ( ) ;
490+ let mut envs: HashMap < String , String > = HashMap :: new ( ) ;
491+ envs. insert ( "key" . to_string ( ) , "value" . to_string ( ) ) ;
492+
493+ let meta = BundleMeta {
494+ junit_props : BundleMetaJunitProps :: default ( ) ,
495+ bundle_upload_id_v2 : String :: with_capacity ( 0 ) ,
496+ debug_props : BundleMetaDebugProps {
497+ command_line : String :: with_capacity ( 0 ) ,
498+ } ,
499+ variant : Some ( "variant" . to_string ( ) ) ,
500+ base_props : BundleMetaBaseProps {
501+ version : META_VERSION . to_string ( ) ,
502+ org : "org" . to_string ( ) ,
503+ repo : repo. clone ( ) ,
504+ cli_version : "0.0.1" . to_string ( ) ,
505+ bundle_upload_id : "00" . to_string ( ) ,
506+ tags : vec ! [ ] ,
507+ file_sets : vec ! [ FileSet :: new(
508+ FileSetType :: Internal ,
509+ vec![ bundled_file. clone( ) ] ,
510+ "*.bin" . to_string( ) ,
511+ None ,
512+ ) ] ,
513+ upload_time_epoch : SystemTime :: now ( )
514+ . duration_since ( UNIX_EPOCH )
515+ . unwrap_or_else ( |_| std:: time:: Duration :: from_secs ( 0 ) )
516+ . as_secs ( ) ,
517+ test_command : Some ( "exit 1" . to_string ( ) ) ,
518+ quarantined_tests : vec ! [ ] ,
519+ os_info : Some ( env:: consts:: OS . to_string ( ) ) ,
520+ codeowners : None ,
521+ envs,
522+ use_uncloned_repo : None ,
523+ } ,
524+ internal_bundled_file : Some ( bundled_file. clone ( ) ) ,
525+ failed_tests : vec ! [ ] ,
526+ } ;
527+
528+ let bundler_util = BundlerUtil :: new ( & meta, None ) ;
529+ let bundle_path = temp_dir. path ( ) . join ( BUNDLE_FILE_NAME ) ;
530+
531+ assert ! ( bundler_util. make_tarball( & bundle_path) . is_ok( ) ) ;
532+ assert ! ( bundle_path. exists( ) ) ;
533+
534+ let tar_file = File :: open ( & bundle_path) . unwrap ( ) ;
535+ let zstd_decoder = zstd:: Decoder :: new ( tar_file) . unwrap ( ) ;
536+ let mut archive = tar:: Archive :: new ( zstd_decoder) ;
537+ let entries = archive. entries ( ) . unwrap ( ) ;
538+
539+ let mut internal_0_count = 0 ;
540+ for entry in entries {
541+ let entry = entry. unwrap ( ) ;
542+ let path = entry. header ( ) . path ( ) . unwrap ( ) ;
543+ if path. to_str ( ) . unwrap ( ) == internal_path {
544+ internal_0_count += 1 ;
545+ }
546+ }
547+
548+ assert_eq ! (
549+ internal_0_count, 1 ,
550+ "Expected 'internal/0' to appear exactly once in the tarball, but it appeared {} times" ,
551+ internal_0_count
552+ ) ;
553+ }
453554}
0 commit comments