From 6f280309aca3a8d327cddb6f6e90969e9d577706 Mon Sep 17 00:00:00 2001 From: rishwanth1995 Date: Tue, 12 Jun 2018 16:13:44 -0400 Subject: [PATCH] delete the report file if ingestprocesscancelled in runexe.py --- pythonExamples/Aug2015DataSourceTutorial/RunExe.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pythonExamples/Aug2015DataSourceTutorial/RunExe.py b/pythonExamples/Aug2015DataSourceTutorial/RunExe.py index 6e51c1dd7b..6b43853f30 100644 --- a/pythonExamples/Aug2015DataSourceTutorial/RunExe.py +++ b/pythonExamples/Aug2015DataSourceTutorial/RunExe.py @@ -136,8 +136,10 @@ class RunExeIngestModule(DataSourceIngestModule): # We'll save our output to a file in the reports folder, named based on EXE and data source ID reportFile = File(Case.getCurrentCase().getCaseDirectory() + "\\Reports" + "\\img_stat-" + str(dataSource.getId()) + ".txt") # Run the EXE, saving output to the report - # NOTE: we should really be checking for if the module has been - # cancelled and then killing the process. + # Check if the ingest is terminated and delete the incomplete report file + # Do not add report to the case tree if the ingest is cancelled before finish. + # This can be done by using IngestJobContext.dataSourceIngestIsCancelled + # See: http://sleuthkit.org/autopsy/docs/api-docs/4.7.0/_ingest_job_context_8java.html self.log(Level.INFO, "Running program on data source") cmd = ArrayList() cmd.add(self.pathToEXE.toString()) @@ -150,5 +152,9 @@ class RunExeIngestModule(DataSourceIngestModule): # Add the report to the case, so it shows up in the tree if not self.context.dataSourceIngestIsCancelled(): Case.getCurrentCase().addReport(reportFile.toString(), "Run EXE", "img_stat output") - + else: + if reportFile.exists(): + if not reportFile.delete(): + self.log(LEVEL.warning,"Error deleting the incomplete report file") + return IngestModule.ProcessResult.OK