Skip to content
Snippets Groups Projects
Unverified Commit 1c7c30a5 authored by Richard Cordovano's avatar Richard Cordovano Committed by GitHub
Browse files

Merge pull request #1959 from APriestman/6378_dspErrorHandling

6378 Change success/error handling for addImageProcess
parents 752fb305 2189255b
Branches
No related tags found
No related merge requests found
...@@ -50,7 +50,6 @@ public static void run(String imagePath) { ...@@ -50,7 +50,6 @@ public static void run(String imagePath) {
} catch (TskDataException ex) { } catch (TskDataException ex) {
Logger.getLogger(Sample.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(Sample.class.getName()).log(Level.SEVERE, null, ex);
} }
process.commit();
// print out all the images found, and their children // print out all the images found, and their children
List<Image> images = sk.getImages(); List<Image> images = sk.getImages();
......
...@@ -468,6 +468,7 @@ public class AddImageProcess { ...@@ -468,6 +468,7 @@ public class AddImageProcess {
private final boolean skipFatFsOrphans; private final boolean skipFatFsOrphans;
private final String imageWriterPath; private final String imageWriterPath;
private volatile long tskAutoDbPointer; private volatile long tskAutoDbPointer;
private long imageId = 0;
private boolean isCanceled; private boolean isCanceled;
private final SleuthkitCase skCase; private final SleuthkitCase skCase;
private JniDbHelper dbHelper; private JniDbHelper dbHelper;
...@@ -498,8 +499,6 @@ private AddImageProcess(String timeZone, boolean addUnallocSpace, boolean skipFa ...@@ -498,8 +499,6 @@ private AddImageProcess(String timeZone, boolean addUnallocSpace, boolean skipFa
/** /**
* Starts the process of adding an image to the case database. * Starts the process of adding an image to the case database.
* Either AddImageProcess.commit or AddImageProcess.revert MUST be
* called after calling AddImageProcess.run.
* *
* @param deviceId An ASCII-printable identifier for the * @param deviceId An ASCII-printable identifier for the
* device associated with the image that * device associated with the image that
...@@ -531,13 +530,15 @@ public void run(String deviceId, String[] imageFilePaths, int sectorSize) throws ...@@ -531,13 +530,15 @@ public void run(String deviceId, String[] imageFilePaths, int sectorSize) throws
* @param sectorSize The sector size (use '0' for autodetect). * @param sectorSize The sector size (use '0' for autodetect).
* @param addDataSourceCallbacks The callbacks to use to send data to ingest (may do nothing). * @param addDataSourceCallbacks The callbacks to use to send data to ingest (may do nothing).
* *
* @return The object ID of the new image.
*
* @throws TskCoreException if a critical error occurs within the * @throws TskCoreException if a critical error occurs within the
* SleuthKit. * SleuthKit.
* @throws TskDataException if a non-critical error occurs within * @throws TskDataException if a non-critical error occurs within
* the SleuthKit (should be OK to continue * the SleuthKit (should be OK to continue
* the process) * the process)
*/ */
public void run(String deviceId, String[] imageFilePaths, int sectorSize, public long run(String deviceId, String[] imageFilePaths, int sectorSize,
AddDataSourceCallbacks addDataSourceCallbacks) throws TskCoreException, TskDataException { AddDataSourceCallbacks addDataSourceCallbacks) throws TskCoreException, TskDataException {
dbHelper = new JniDbHelper(skCase, addDataSourceCallbacks); dbHelper = new JniDbHelper(skCase, addDataSourceCallbacks);
getTSKReadLock(); getTSKReadLock();
...@@ -557,10 +558,15 @@ public void run(String deviceId, String[] imageFilePaths, int sectorSize, ...@@ -557,10 +558,15 @@ public void run(String deviceId, String[] imageFilePaths, int sectorSize,
} }
if (imageHandle != 0) { if (imageHandle != 0) {
runAddImgNat(tskAutoDbPointer, deviceId, imageHandle, timeZone, imageWriterPath); runAddImgNat(tskAutoDbPointer, deviceId, imageHandle, timeZone, imageWriterPath);
} }
} finally { } finally {
finishAddImageProcess();
releaseTSKReadLock(); releaseTSKReadLock();
} }
synchronized (this) {
return imageId;
}
} }
/** /**
...@@ -583,58 +589,62 @@ public synchronized void stop() throws TskCoreException { ...@@ -583,58 +589,62 @@ public synchronized void stop() throws TskCoreException {
releaseTSKReadLock(); releaseTSKReadLock();
} }
} }
/**
* Call at the end of the add image process regardless of the error/canceled state.
*
* Note that the new image is no longer deleted on error/cancellation
*
* If the process was not canceled, will add the final batch of files to the database
* and submit for any further processing through the callback.
*
* @throws TskCoreException
*/
private synchronized void finishAddImageProcess() throws TskCoreException {
if (tskAutoDbPointer == 0) {
return;
}
// If the process wasn't cancelled, finish up processing the
// remaining files.
if (! this.isCanceled && dbHelper != null) {
dbHelper.finish();
}
// Free the auto DB pointer and get the image ID
imageId = finishAddImgNat(tskAutoDbPointer);
tskAutoDbPointer = 0;
skCase.addDataSourceToHasChildrenMap();
}
/** /**
* Rolls back the process of adding an image to the case database * This no longer needs to be called.
* that was started by calling AddImageProcess.run.
* *
* @throws TskCoreException if a critical error occurs within the * @throws TskCoreException if a critical error occurs within the
* SleuthKit. * SleuthKit.
*
* @deprecated No longer necessary
*/ */
@Deprecated
public synchronized void revert() throws TskCoreException { public synchronized void revert() throws TskCoreException {
getTSKReadLock(); // No-op
try {
if (tskAutoDbPointer == 0) {
throw new TskCoreException("AddImgProcess::revert: AutoDB pointer is NULL");
}
// Delete the object in the native code
finishAddImgNat(tskAutoDbPointer);
tskAutoDbPointer = 0;
} finally {
releaseTSKReadLock();
}
} }
/** /**
* Completes the process of adding an image to the case database * This no longer needs to be called. Will simply return the
* that was started by calling AddImageProcess.run. * object ID of the new image.
* *
* @return The object id of the image that was added. * @return The object id of the image that was added.
* *
* @throws TskCoreException if a critical error occurs within the * @throws TskCoreException if a critical error occurs within the
* SleuthKit. * SleuthKit.
*
* @deprecated No longer necessary
*/ */
@Deprecated
public synchronized long commit() throws TskCoreException { public synchronized long commit() throws TskCoreException {
getTSKReadLock(); return imageId;
try {
if (tskAutoDbPointer == 0) {
throw new TskCoreException("AddImgProcess::commit: AutoDB pointer is NULL");
}
if (dbHelper != null) {
dbHelper.finish();
}
// Get the image ID and delete the object in the native code
long id = finishAddImgNat(tskAutoDbPointer);
tskAutoDbPointer = 0;
skCase.addDataSourceToHasChildrenMap();
return id;
} finally {
releaseTSKReadLock();
}
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment