@@ -524,24 +524,29 @@ def make_package(args):
524
524
for patch_name in os .listdir (join ('src' , 'patches' )):
525
525
patch_path = join ('src' , 'patches' , patch_name )
526
526
print ("Applying patch: " + str (patch_path ))
527
+
528
+ # -N: insist this is FORWARD patch, don't reverse apply
529
+ # -p1: strip first path component
530
+ # -t: batch mode, don't ask questions
531
+ patch_command = ["patch" , "-N" , "-p1" , "-t" , "-i" , patch_path ]
532
+
527
533
try :
528
- subprocess .check_output ([
529
- # -N: insist this is FORWARd patch, don't reverse apply
530
- # -p1: strip first path component
531
- # -t: batch mode, don't ask questions
532
- "patch" , "-N" , "-p1" , "-t" , "-i" , patch_path
533
- ])
534
+ # Use a dry run to establish whether the patch is already applied.
535
+ # If we don't check this, the patch may be partially applied (which is bad!)
536
+ subprocess .check_output (patch_command + ["--dry-run" ])
534
537
except subprocess .CalledProcessError as e :
535
538
if e .returncode == 1 :
536
- # Return code 1 means it didn't apply, this will
537
- # usually mean it is already applied.
538
- print ("Warning: failed to apply patch (" +
539
- "exit code 1), " +
540
- "assuming it is already applied: " +
541
- str (patch_path )
542
- )
539
+ # Return code 1 means not all hunks could be applied, this usually
540
+ # means the patch is already applied.
541
+ print ("Warning: failed to apply patch (exit code 1), "
542
+ "assuming it is already applied: " ,
543
+ str (patch_path ))
543
544
else :
544
545
raise e
546
+ else :
547
+ # The dry run worked, so do the real thing
548
+ subprocess .check_output (patch_command )
549
+
545
550
546
551
547
552
def parse_args_and_make_package (args = None ):
0 commit comments