From 9db0cf2b7e6488abfd66bc02c9e9bf9de7f9273c Mon Sep 17 00:00:00 2001 From: Joe Ho Date: Fri, 13 Sep 2019 13:39:54 -0400 Subject: [PATCH] Fix PR comments. Use thread.join to wait for AddMultipleImageTask thread. --- .../dsp/AddLogicalImageTask.java | 23 ++++---- .../dsp/AddMultipleImageTask.java | 57 +++++++++---------- .../dsp/LogicalImagerDSProcessor.java | 3 +- 3 files changed, 43 insertions(+), 40 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/logicalimager/dsp/AddLogicalImageTask.java b/Core/src/org/sleuthkit/autopsy/logicalimager/dsp/AddLogicalImageTask.java index df3c0f8d14..16481c26a8 100644 --- a/Core/src/org/sleuthkit/autopsy/logicalimager/dsp/AddLogicalImageTask.java +++ b/Core/src/org/sleuthkit/autopsy/logicalimager/dsp/AddLogicalImageTask.java @@ -72,9 +72,10 @@ final class AddLogicalImageTask implements Runnable { private final Case currentCase; private volatile boolean cancelled; - private boolean addingInterestingFiles; + private volatile boolean addingInterestingFiles; private AddMultipleImageTask addMultipleImageTask; - private boolean createVHD; + private Thread multipleImageThread; + private volatile boolean createVHD; private long totalFiles; private Map imagePathToObjIdMap; @@ -183,7 +184,8 @@ final class AddLogicalImageTask implements Runnable { return; } - AddDataSourceCallback privateCallback = null; + addMultipleImageTask = null; + AddDataSourceCallback privateCallback = new AddDataSourceCallback(); List newDataSources = new ArrayList<>(); if (imagePaths.isEmpty()) { @@ -213,13 +215,14 @@ final class AddLogicalImageTask implements Runnable { createVHD = true; // ingest the VHDs try { - privateCallback = new AddDataSourceCallback(); addMultipleImageTask = new AddMultipleImageTask(deviceId, imagePaths, timeZone , progressMonitor, privateCallback); - addMultipleImageTask.run(); - if (privateCallback.getResult() == DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS) { - // TODO: Delete destination directory when 5453 (VHD file is not closed upon revert) is fixed. - // bait out - callback.done(privateCallback.getResult(), privateCallback.getErrorMessages(), privateCallback.getNewDataSources()); + multipleImageThread = new Thread(addMultipleImageTask); + multipleImageThread.start(); + try { + multipleImageThread.join(); + } catch (InterruptedException ex) { + LOGGER.log(Level.SEVERE, "Add Image interrupted", ex); // NON-NLS + callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS, errorList, emptyDataSources); return; } } catch (NoCurrentCaseException ex) { @@ -235,7 +238,7 @@ final class AddLogicalImageTask implements Runnable { addingInterestingFiles = true; addInterestingFiles(Paths.get(dest.toString(), resultsFilename), createVHD); progressMonitor.setProgressText(Bundle.AddLogicalImageTask_doneAddingInterestingFiles()); - if (addMultipleImageTask != null && privateCallback != null) { + if (createVHD) { callback.done(privateCallback.getResult(), privateCallback.getErrorMessages(), privateCallback.getNewDataSources()); } else { callback.done(DataSourceProcessorCallback.DataSourceProcessorResult.NO_ERRORS, errorList, newDataSources); diff --git a/Core/src/org/sleuthkit/autopsy/logicalimager/dsp/AddMultipleImageTask.java b/Core/src/org/sleuthkit/autopsy/logicalimager/dsp/AddMultipleImageTask.java index f5f64665cf..f19330015a 100644 --- a/Core/src/org/sleuthkit/autopsy/logicalimager/dsp/AddMultipleImageTask.java +++ b/Core/src/org/sleuthkit/autopsy/logicalimager/dsp/AddMultipleImageTask.java @@ -213,14 +213,15 @@ class AddMultipleImageTask implements Runnable { tskAddImageProcessStopped = true; if (addImageProcess != null) { try { + /* + * All this does is set a flag that will make the TSK add + * image process exit when the flag is checked between + * processing steps. The state of the flag is not + * accessible, so record it here so that it is known that + * the revert method of the process object needs to be + * called. + */ addImageProcess.stop(); - addImageProcess.revert(); - if (tskAddImageProcessStopped) { - List errorMessages = new ArrayList<>(); - List emptyDataSources = new ArrayList<>(); - errorMessages.add(Bundle.AddMultipleImageTask_cancelled()); - callback.done(DataSourceProcessorResult.CRITICAL_ERRORS, errorMessages, emptyDataSources); - } } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Cancellation: addImagePRocess.stop failed", ex); // NON-NLS } @@ -295,34 +296,32 @@ class AddMultipleImageTask implements Runnable { return; } - if (!tskAddImageProcessStopped) { - /* - * Try to commit the results of the add image process, retrieve the new - * image from the case database, and add it to the list of new data - * sources to be returned via the callback. - */ - try { - long imageId = addImageProcess.commit(); - Image dataSource = currentCase.getSleuthkitCase().getImageById(imageId); - newDataSources.add(dataSource); + /* + * Try to commit the results of the add image process, retrieve the new + * image from the case database, and add it to the list of new data + * sources to be returned via the callback. + */ + try { + long imageId = addImageProcess.commit(); + Image dataSource = currentCase.getSleuthkitCase().getImageById(imageId); + newDataSources.add(dataSource); - /* + /* * Verify the size of the new image. Note that it may not be what is * expected, but at least part of it was added to the case. - */ - String verificationError = dataSource.verifyImageSize(); - if (!verificationError.isEmpty()) { - errorMessages.add(Bundle.AddMultipleImageTask_nonCriticalErrorAdding(imageFilePath, deviceId, verificationError)); - } - } catch (TskCoreException ex) { - /* + */ + String verificationError = dataSource.verifyImageSize(); + if (!verificationError.isEmpty()) { + errorMessages.add(Bundle.AddMultipleImageTask_nonCriticalErrorAdding(imageFilePath, deviceId, verificationError)); + } + } catch (TskCoreException ex) { + /* * The add image process commit failed or querying the case database * for the newly added image failed. Either way, this is a critical * error. - */ - errorMessages.add(Bundle.AddMultipleImageTask_criticalErrorAdding(imageFilePath, deviceId, ex.getLocalizedMessage())); - criticalErrorOccurred = true; - } + */ + errorMessages.add(Bundle.AddMultipleImageTask_criticalErrorAdding(imageFilePath, deviceId, ex.getLocalizedMessage())); + criticalErrorOccurred = true; } } } diff --git a/Core/src/org/sleuthkit/autopsy/logicalimager/dsp/LogicalImagerDSProcessor.java b/Core/src/org/sleuthkit/autopsy/logicalimager/dsp/LogicalImagerDSProcessor.java index 4cd8ff162e..a3a2632374 100644 --- a/Core/src/org/sleuthkit/autopsy/logicalimager/dsp/LogicalImagerDSProcessor.java +++ b/Core/src/org/sleuthkit/autopsy/logicalimager/dsp/LogicalImagerDSProcessor.java @@ -36,6 +36,7 @@ import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor; import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorCallback; import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorProgressMonitor; +import org.sleuthkit.autopsy.coreutils.TimeStampUtils; import org.sleuthkit.datamodel.Content; /** @@ -173,7 +174,7 @@ public final class LogicalImagerDSProcessor implements DataSourceProcessor { JOptionPane.YES_NO_OPTION); if (showConfirmDialog == YES_OPTION) { // Get unique dest directory - String uniqueDirectory = imageDirPath.getFileName() + "_" + UUID.randomUUID(); + String uniqueDirectory = imageDirPath.getFileName() + "_" + TimeStampUtils.createTimeStamp(); dest = Paths.get(logicalImagerDir.toString(), uniqueDirectory).toFile(); } else { String msg = Bundle.LogicalImagerDSProcessor_directoryAlreadyExists(dest.toString());