@@ -426,31 +426,31 @@ def assemble_zip(inputs,
426
426
contanining analysis related information into a zip file which
427
427
will be sent to the server.
428
428
"""
429
- files_to_compress = set ( )
429
+ files_to_compress : Dict [ str , set ] = defaultdict ( set )
430
430
analyzer_result_file_paths = []
431
431
stats = StorageZipStatistics ()
432
432
433
- # resultfile_to_metadata = dict()
434
-
435
433
for dir_path , file_paths in report_file .analyzer_result_files (inputs ):
436
434
analyzer_result_file_paths .extend (file_paths )
437
435
438
436
metadata_file_path = os .path .join (dir_path , 'metadata.json' )
439
437
if os .path .exists (metadata_file_path ):
440
- files_to_compress . add (metadata_file_path )
441
- # for src_dir_path, mip in MetadataInfoParser (metadata_file_path):
438
+ files_to_compress [ os . path . dirname (metadata_file_path )] \
439
+ . add (metadata_file_path )
442
440
443
441
skip_file_path = os .path .join (dir_path , 'skip_file' )
444
442
if os .path .exists (skip_file_path ):
445
443
with open (skip_file_path , 'r' ) as f :
446
444
LOG .info ("Found skip file %s with the following content:\n %s" ,
447
445
skip_file_path , f .read ())
448
446
449
- files_to_compress .add (skip_file_path )
447
+ files_to_compress [os .path .dirname (skip_file_path )] \
448
+ .add (skip_file_path )
450
449
451
450
review_status_file_path = os .path .join (dir_path , 'review_status.yaml' )
452
451
if os .path .exists (review_status_file_path ):
453
- files_to_compress .add (review_status_file_path )
452
+ files_to_compress [os .path .dirname (review_status_file_path )]\
453
+ .add (review_status_file_path )
454
454
455
455
LOG .debug (f"Processing { len (analyzer_result_file_paths )} report files ..." )
456
456
@@ -463,7 +463,7 @@ def assemble_zip(inputs,
463
463
changed_files = set ()
464
464
file_paths = set ()
465
465
file_report_positions : FileReportPositions = defaultdict (set )
466
- unique_reports = dict ( )
466
+ unique_reports : Dict [ str , Dict [ str , List [ Report ]]] = defaultdict ( dict )
467
467
468
468
unique_report_hashes = set ()
469
469
for file_path , reports in analyzer_result_file_reports .items ():
@@ -477,7 +477,8 @@ def assemble_zip(inputs,
477
477
report_path_hash = get_report_path_hash (report )
478
478
if report_path_hash not in unique_report_hashes :
479
479
unique_report_hashes .add (report_path_hash )
480
- unique_reports .setdefault (report .analyzer_name , []) \
480
+ unique_reports [os .path .dirname (file_path )]\
481
+ .setdefault (report .analyzer_name , []) \
481
482
.append (report )
482
483
stats .add_report (report )
483
484
@@ -486,15 +487,17 @@ def assemble_zip(inputs,
486
487
487
488
# TODO: Doesn't support storing multiple report dirs.
488
489
if unique_reports :
489
- for analyzer_name , reports in unique_reports .items ():
490
- if not analyzer_name :
491
- analyzer_name = 'unknown'
492
- _ , tmpfile = tempfile .mkstemp (f'-{ analyzer_name } .plist' )
493
-
494
- report_file .create (tmpfile , reports , checker_labels ,
495
- AnalyzerInfo (analyzer_name ))
496
- LOG .debug (f"Stored '{ analyzer_name } ' unique reports in { tmpfile } ." )
497
- files_to_compress .add (tmpfile )
490
+ for dirname , analyzer_reports in unique_reports .items ():
491
+ for analyzer_name , reports in analyzer_reports .items ():
492
+ if not analyzer_name :
493
+ analyzer_name = 'unknown'
494
+ _ , tmpfile = tempfile .mkstemp (f'-{ analyzer_name } .plist' )
495
+
496
+ report_file .create (tmpfile , reports , checker_labels ,
497
+ AnalyzerInfo (analyzer_name ))
498
+ LOG .debug (f"Stored '{ analyzer_name } ' unique reports "
499
+ f"in { tmpfile } ." )
500
+ files_to_compress [dirname ].add (tmpfile )
498
501
499
502
if changed_files :
500
503
reports_helper .dump_changed_files (changed_files )
@@ -552,15 +555,13 @@ def assemble_zip(inputs,
552
555
with zipfile .ZipFile (zip_file , 'a' , allowZip64 = True ) as zipf :
553
556
# Add the files to the zip which will be sent to the server.
554
557
555
- assert len (inputs ) > 0
556
- if len (files_to_compress ) > 0 :
557
- # Create a unique report directory name.
558
- report_dir_name = hashlib .md5 (os .path .dirname (
559
- list (files_to_compress )[0 ]).encode ('utf-8' )).hexdigest ()
560
-
561
- for file_path in files_to_compress :
558
+ for dirname , files in files_to_compress .items ():
559
+ for file_path in files :
562
560
_ , file_name = os .path .split (file_path )
563
561
562
+ # Create a unique report directory name.
563
+ report_dir_name = \
564
+ hashlib .md5 (dirname .encode ('utf-8' )).hexdigest ()
564
565
zip_target = \
565
566
os .path .join ('reports' , report_dir_name , file_name )
566
567
zipf .write (file_path , zip_target )
0 commit comments