@@ -110,15 +110,17 @@ async function extractAndParseReports(dir: string, shardFiles: string[], interna
110110 const shardEvents : { file : string , localPath : string , metadata : BlobReportMetadata , parsedEvents : JsonEvent [ ] } [ ] = [ ] ;
111111 await fs . promises . mkdir ( path . join ( dir , 'resources' ) , { recursive : true } ) ;
112112
113+ const reportNames = new UniqueFileNameGenerator ( ) ;
113114 for ( const file of shardFiles ) {
114115 const absolutePath = path . join ( dir , file ) ;
115116 printStatus ( `extracting: ${ relativeFilePath ( absolutePath ) } ` ) ;
116117 const zipFile = new ZipFile ( absolutePath ) ;
117118 const entryNames = await zipFile . entries ( ) ;
118119 for ( const entryName of entryNames . sort ( ) ) {
119- const fileName = path . join ( dir , entryName ) ;
120+ let fileName = path . join ( dir , entryName ) ;
120121 const content = await zipFile . read ( entryName ) ;
121122 if ( entryName . endsWith ( '.jsonl' ) ) {
123+ fileName = reportNames . makeUnique ( fileName ) ;
122124 const parsedEvents = parseCommonEvents ( content ) ;
123125 // Passing reviver to JSON.parse doesn't work, as the original strings
124126 // keep beeing used. To work around that we traverse the parsed events
@@ -285,6 +287,27 @@ function printStatusToStdout(message: string) {
285287 process . stdout . write ( `${ message } \n` ) ;
286288}
287289
290+ class UniqueFileNameGenerator {
291+ private _usedNames = new Set < string > ( ) ;
292+
293+ makeUnique ( name : string ) : string {
294+ if ( ! this . _usedNames . has ( name ) ) {
295+ this . _usedNames . add ( name ) ;
296+ return name ;
297+ }
298+ const extension = path . extname ( name ) ;
299+ name = name . substring ( 0 , name . length - extension . length ) ;
300+ let index = 0 ;
301+ while ( true ) {
302+ const candidate = `${ name } -${ ++ index } ${ extension } ` ;
303+ if ( ! this . _usedNames . has ( candidate ) ) {
304+ this . _usedNames . add ( candidate ) ;
305+ return candidate ;
306+ }
307+ }
308+ }
309+ }
310+
288311class IdsPatcher {
289312 constructor ( private _stringPool : StringInternPool , private _reportName : string | undefined , private _salt : string ) {
290313 }
0 commit comments