@@ -159,8 +159,11 @@ def _copy_planner(self, source_path, target_filename):
159159 if not os .path .exists (planner_dir ):
160160 os .makedirs (planner_dir )
161161 target_path = os .path .join (planner_dir , target_filename )
162- shutil .copyfile (source_path , target_path )
163- self .log .debug ('Copied planner to %s' , target_path )
162+ if os .path .exists (target_path ):
163+ self .log .debug ('Planner %s already exists. Skipping.' , target_path )
164+ else :
165+ shutil .copyfile (source_path , target_path )
166+ self .log .debug ('Copied planner to %s' , target_path )
164167
165168 @staticmethod
166169 def _is_planner (data ):
@@ -226,8 +229,11 @@ async def _write_adversary(self, data):
226229 os .makedirs (d )
227230
228231 file_path = os .path .join (d , '%s.yml' % data ['id' ])
229- with open (file_path , 'w' ) as f :
230- f .write (yaml .dump (data ))
232+ if os .path .exists (file_path ):
233+ self .log .debug ('Adversary profile %s already exists. Skipping.' , file_path )
234+ else :
235+ with open (file_path , 'w' ) as f :
236+ f .write (yaml .dump (data ))
231237
232238 async def _save_adversary (self , id , name , description , abilities ):
233239 adversary = dict (
@@ -249,8 +255,11 @@ async def _write_ability(self, data):
249255 if not os .path .exists (d ):
250256 os .makedirs (d )
251257 file_path = os .path .join (d , '%s.yml' % data ['id' ])
252- with open (file_path , 'w' ) as f :
253- f .write (yaml .dump ([data ]))
258+ if os .path .exists (file_path ):
259+ self .log .debug ('Ability file %s already exists. Skipping.' , file_path )
260+ else :
261+ with open (file_path , 'w' ) as f :
262+ f .write (yaml .dump ([data ]))
254263
255264 @staticmethod
256265 def get_privilege (executors ):
@@ -344,5 +353,8 @@ async def _write_source(self, data):
344353 os .makedirs (d )
345354
346355 file_path = os .path .join (d , '%s.yml' % data ['id' ])
347- with open (file_path , 'w' ) as f :
348- f .write (yaml .dump (data ))
356+ if os .path .exists (file_path ):
357+ self .log .debug ('Fact source file %s already exists. Skipping.' , file_path )
358+ else :
359+ with open (file_path , 'w' ) as f :
360+ f .write (yaml .dump (data ))
0 commit comments