20 package org.sleuthkit.autopsy.casemodule;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
26 import java.util.logging.Level;
28 import org.openide.util.NbBundle;
48 class AddImageTask
implements Runnable {
50 private final Logger logger = Logger.getLogger(AddImageTask.class.getName());
52 private final Case currentCase;
55 private final Object lock =
new Object();
56 private volatile boolean cancelRequested =
false;
59 private boolean reverted =
false;
62 private boolean hasCritError =
false;
64 private final List<String> errorList =
new ArrayList<>();
66 private final DataSourceProcessorProgressMonitor progressMonitor;
67 private final DataSourceProcessorCallback callbackObj;
69 private final List<Content> newContents = Collections.synchronizedList(
new ArrayList<Content>());
71 private SleuthkitJNI.CaseDbHandle.AddImageProcess addImageProcess;
72 private Thread dirFetcher;
74 private final String imagePath;
88 this.progressMonitor = aProgressMonitor;
98 while (!Thread.currentThread().isInterrupted()) {
99 String currDir = process.currentDirectory();
100 if (currDir != null) {
101 if (!currDir.isEmpty() ) {
103 NbBundle.getMessage(
this.getClass(),
"AddImageTask.run.progress.adding",
111 }
catch (InterruptedException ie) {
122 this.imagePath = imgPath;
124 this.noFatOrphans = noOrphans;
126 this.callbackObj = cbObj;
127 this.progressMonitor = aProgressMonitor;
141 currentCase.getSleuthkitCase().acquireExclusiveLock();
142 addImageProcess = currentCase.makeAddImageProcess(timeZone,
true, noFatOrphans);
143 dirFetcher =
new Thread(
new CurrentDirectoryFetcher(progressMonitor, addImageProcess));
145 progressMonitor.setIndeterminate(
true);
146 progressMonitor.setProgress(0);
148 addImageProcess.run(
new String[]{this.imagePath});
149 }
catch (TskCoreException ex) {
150 logger.log(Level.SEVERE,
"Core errors occurred while running add image. ", ex);
152 errorList.add(ex.getMessage());
153 }
catch (TskDataException ex) {
154 logger.log(Level.WARNING,
"Data errors occurred while running add image. ", ex);
155 errorList.add(ex.getMessage());
159 currentCase.getSleuthkitCase().releaseExclusiveLock();
169 private void commitImage() throws Exception {
173 imageId = addImageProcess.commit();
174 }
catch (TskCoreException e) {
175 logger.log(Level.WARNING,
"Errors occured while committing the image", e);
176 errorList.add(e.getMessage());
180 Image newImage = currentCase.getSleuthkitCase().getImageById(imageId);
183 String verificationErrors = newImage.verifyImageSize();
184 if (verificationErrors.equals(
"") ==
false) {
186 errorList.add(verificationErrors);
190 newContents.add(newImage);
193 logger.log(Level.INFO,
"Image committed, imageId: {0}", imageId);
194 logger.log(Level.INFO, PlatformUtil.getAllMemUsageInfo());
202 private void postProcess() {
205 dirFetcher.interrupt();
207 if (cancelRequested() || hasCritError) {
208 logger.log(Level.WARNING,
"Critical errors or interruption in add image process. Image will not be committed.");
212 if (!errorList.isEmpty()) {
213 logger.log(Level.INFO,
"There were errors that occured in add image process");
217 if (!(cancelRequested() || hasCritError)) {
219 if (addImageProcess != null) {
223 }
catch (Exception ex) {
224 errorList.add(ex.getMessage());
226 logger.log(Level.SEVERE,
"Error adding image to case.", ex);
229 logger.log(Level.SEVERE,
"Missing image process object");
233 progressMonitor.setProgress(100);
234 }
catch (Exception ex) {
236 errorList.add(ex.getMessage());
238 logger.log(Level.WARNING,
"Unexpected errors occurred while running post add image cleanup. ", ex);
239 logger.log(Level.SEVERE,
"Error adding image to case", ex);
244 if (!cancelRequested()) {
252 private void doCallBack()
254 DataSourceProcessorCallback.DataSourceProcessorResult result;
257 result = DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS;
259 else if (!errorList.isEmpty()) {
260 result = DataSourceProcessorCallback.DataSourceProcessorResult.NONCRITICAL_ERRORS;
263 result = DataSourceProcessorCallback.DataSourceProcessorResult.NO_ERRORS;
267 callbackObj.done(result, errorList, newContents);
273 public void cancelTask() {
275 synchronized (lock) {
276 cancelRequested =
true;
280 catch (Exception ex) {
281 logger.log(Level.SEVERE,
"Failed to interrupt the add image task...");
289 private void interrupt() throws Exception {
292 logger.log(Level.INFO,
"interrupt() add image process");
293 addImageProcess.stop();
294 }
catch (TskCoreException ex) {
295 throw new Exception(NbBundle.getMessage(
this.getClass(),
"AddImageTask.interrupt.exception.msg"), ex);
302 private void revert() {
305 logger.log(Level.INFO,
"Revert after add image process");
307 addImageProcess.revert();
308 }
catch (TskCoreException ex) {
309 logger.log(Level.WARNING,
"Error reverting add image process", ex);
315 private boolean cancelRequested() {
316 synchronized (lock) {
317 return cancelRequested;
void setProgressText(String text)
static Case getCurrentCase()