@@ -517,15 +517,32 @@ def extract_wildcard_paths(path):
517
517
518
518
if cmdline .rebuild :
519
519
print ("First performing cleanup." )
520
- print (" Deleting " + cmdline .temp_dir )
521
- if os .path .exists (cmdline .temp_dir ):
522
- shutil .rmtree (cmdline .temp_dir )
523
- print (" Deleting " + cmdline .results_dir )
524
- if os .path .exists (cmdline .results_dir ):
525
- shutil .rmtree (cmdline .results_dir )
526
- print (" Deleting " + cmdline .common_dir )
527
- if os .path .exists (cmdline .common_dir ):
528
- shutil .rmtree (cmdline .common_dir )
520
+
521
+ if cmdline .prepare_scan is not None :
522
+ if os .path .exists (cmdline .temp_dir ):
523
+ print (" Deleting " + cmdline .temp_dir )
524
+ shutil .rmtree (cmdline .temp_dir )
525
+ if os .path .exists (cmdline .results_dir ):
526
+ print (" Deleting " + cmdline .results_dir )
527
+ shutil .rmtree (cmdline .results_dir )
528
+ if os .path .exists (cmdline .common_dir ):
529
+ print (" Deleting " + cmdline .common_dir )
530
+ shutil .rmtree (cmdline .common_dir )
531
+ elif cmdline .run_scan is not None :
532
+
533
+ # If we're running a scan, clear down all non-configuration files ready for a re-run.
534
+ entry_point_directories = []
535
+ if cmdline .run_scan == '' :
536
+ entry_point_directories = [os .path .join (cmdline .results_dir , ep_folder ) for ep_folder in os .listdir (cmdline .results_dir )]
537
+ else :
538
+ entry_point_directories .append (os .path .dirname (cmdline .run_scan ))
539
+
540
+ # If the folder contains at least one of our command files, we can assume it's safe to delete from.
541
+ command_files = {"command_line.json" , "config.json" , "program.json" }
542
+ for deletable_folder in [os .path .join (folder , deletable_entry )
543
+ for folder in entry_point_directories if command_files .intersection (os .listdir (folder ))
544
+ for deletable_entry in os .listdir (folder ) if os .path .isdir (os .path .join (folder , deletable_entry ))]:
545
+ shutil .rmtree (deletable_folder )
529
546
530
547
if not os .path .exists (cmdline .results_dir ):
531
548
os .makedirs (cmdline .results_dir )
0 commit comments