30
30
from winsign .crypto import load_pem_certs
31
31
32
32
from signingscript import task , utils
33
- from signingscript .createprecomplete import generate_precomplete
34
33
from signingscript .exceptions import SigningScriptError
35
34
from signingscript .rcodesign import RCodesignError , rcodesign_notarize , rcodesign_notary_wait , rcodesign_staple
36
35
@@ -307,18 +306,20 @@ async def sign_widevine_zip(context, orig_path, fmt):
307
306
# Extract all files so we can create `precomplete` with the full
308
307
# file list
309
308
all_files = await _extract_zipfile (context , orig_path , tmp_dir = tmp_dir )
309
+ signed_files = {}
310
310
tasks = []
311
311
# Sign the appropriate inner files
312
312
for from_ , fmt in files_to_sign .items ():
313
313
from_ = os .path .join (tmp_dir , from_ )
314
314
to = f"{ from_ } .sig"
315
315
tasks .append (asyncio .ensure_future (sign_widevine_with_autograph (context , from_ , "blessed" in fmt , to = to )))
316
316
all_files .append (to )
317
+ signed_files [from_ ] = to
317
318
await raise_future_exceptions (tasks )
318
319
remove_extra_files (tmp_dir , all_files )
319
- # Regenerate the `precomplete` file, which is used for cleanup before
320
+ # Update the `precomplete` file, which is used for cleanup before
320
321
# applying a complete mar.
321
- _run_generate_precomplete (context , tmp_dir )
322
+ _update_precomplete (context , tmp_dir , signed_files )
322
323
await _create_zipfile (context , orig_path , all_files , mode = "w" , tmp_dir = tmp_dir )
323
324
return orig_path
324
325
@@ -358,6 +359,7 @@ async def sign_widevine_tar(context, orig_path, fmt):
358
359
# Extract all files so we can create `precomplete` with the full
359
360
# file list
360
361
all_files = await _extract_tarfile (context , orig_path , compression , tmp_dir = tmp_dir )
362
+ signed_files = {}
361
363
tasks = []
362
364
# Sign the appropriate inner files
363
365
for from_ , fmt in files_to_sign .items ():
@@ -371,11 +373,12 @@ async def sign_widevine_tar(context, orig_path, fmt):
371
373
makedirs (os .path .dirname (to ))
372
374
tasks .append (asyncio .ensure_future (sign_widevine_with_autograph (context , from_ , "blessed" in fmt , to = to )))
373
375
all_files .append (to )
376
+ signed_files [from_ ] = to
374
377
await raise_future_exceptions (tasks )
375
378
remove_extra_files (tmp_dir , all_files )
376
- # Regenerate the `precomplete` file, which is used for cleanup before
379
+ # Update the `precomplete` file, which is used for cleanup before
377
380
# applying a complete mar.
378
- _run_generate_precomplete (context , tmp_dir )
381
+ _update_precomplete (context , tmp_dir , signed_files )
379
382
await _create_tarfile (context , orig_path , all_files , compression , tmp_dir = tmp_dir )
380
383
return orig_path
381
384
@@ -577,16 +580,25 @@ def _get_omnija_signing_files(file_list):
577
580
return files
578
581
579
582
580
- # _run_generate_precomplete {{{1
581
- def _run_generate_precomplete (context , tmp_dir ):
583
+ # _update_precomplete {{{1
584
+ def _update_precomplete (context , tmp_dir , signed_files ):
582
585
"""Regenerate `precomplete` file with widevine sig paths for complete mar."""
583
586
log .info ("Generating `precomplete` file..." )
584
- path = _ensure_one_precomplete (tmp_dir , "before" )
585
- with open (path , "r" ) as fh :
587
+ precomplete = _ensure_one_precomplete (tmp_dir )
588
+ with open (precomplete , "r" ) as fh :
586
589
before = fh .readlines ()
587
- generate_precomplete (os .path .dirname (path ))
588
- path = _ensure_one_precomplete (tmp_dir , "after" )
589
- with open (path , "r" ) as fh :
590
+ with open (precomplete , "w" ) as fh :
591
+ for line in before :
592
+ fh .write (line )
593
+ instr , path = line .strip ().split (None , 1 )
594
+ if instr != "remove" :
595
+ continue
596
+ if not path or path [0 ] != '"' or path [- 1 ] != '"' :
597
+ continue
598
+ if path [1 :- 1 ] not in signed_files :
599
+ continue
600
+ fh .write ('remove "{}"\n ' .format (signed_files [path [1 :- 1 ]]))
601
+ with open (precomplete , "r" ) as fh :
590
602
after = fh .readlines ()
591
603
# Create diff file
592
604
diff_path = os .path .join (context .config ["work_dir" ], "precomplete.diff" )
@@ -597,14 +609,14 @@ def _run_generate_precomplete(context, tmp_dir):
597
609
598
610
599
611
# _ensure_one_precomplete {{{1
600
- def _ensure_one_precomplete (tmp_dir , adj ):
612
+ def _ensure_one_precomplete (tmp_dir ):
601
613
"""Ensure we only have one `precomplete` file in `tmp_dir`."""
602
614
return get_single_item_from_sequence (
603
615
glob .glob (os .path .join (tmp_dir , "**" , "precomplete" ), recursive = True ),
604
616
condition = lambda _ : True ,
605
617
ErrorClass = SigningScriptError ,
606
618
no_item_error_message = 'No `precomplete` file found in "{}"' .format (tmp_dir ),
607
- too_many_item_error_message = 'More than one `precomplete` file {} in "{}"' .format (adj , tmp_dir ),
619
+ too_many_item_error_message = 'More than one `precomplete` file in "{}"' .format (tmp_dir ),
608
620
)
609
621
610
622
0 commit comments