diff --git a/bindings/java/src/org/sleuthkit/datamodel/Examples/Sample.java b/bindings/java/src/org/sleuthkit/datamodel/Examples/Sample.java index 01c2504980304f61e174835fccd4bee43816121e..c6b3031b60a05f378b21fff9d7af28213fb20ed3 100755 --- a/bindings/java/src/org/sleuthkit/datamodel/Examples/Sample.java +++ b/bindings/java/src/org/sleuthkit/datamodel/Examples/Sample.java @@ -50,7 +50,6 @@ public static void run(String imagePath) { } catch (TskDataException ex) { Logger.getLogger(Sample.class.getName()).log(Level.SEVERE, null, ex); } - process.commit(); // print out all the images found, and their children List<Image> images = sk.getImages(); diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java index 09bcefcb4c7bcdf2763769d5d2266132f017f27c..7ff07c2f889dbc6fa6db186973377f64375171bd 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java @@ -471,6 +471,7 @@ public class AddImageProcess { private final boolean skipFatFsOrphans; private final String imageWriterPath; private volatile long tskAutoDbPointer; + private long imageId = 0; private boolean isCanceled; private final SleuthkitCase skCase; private JniDbHelper dbHelper; @@ -501,8 +502,6 @@ private AddImageProcess(String timeZone, boolean addUnallocSpace, boolean skipFa /** * 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 * device associated with the image that @@ -534,16 +533,19 @@ public void run(String deviceId, String[] imageFilePaths, int sectorSize) throws * @param sectorSize The sector size (use '0' for autodetect). * @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 * SleuthKit. * @throws TskDataException if a non-critical error occurs within * the SleuthKit (should be OK to continue * 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 { Image img = addImageToDatabase(skCase, imageFilePaths, sectorSize, "", "", "", "", deviceId); - run(deviceId, img, sectorSize, addDataSourceCallbacks); + run(deviceId, img, sectorSize, addDataSourceCallbacks); + return img.getId(); } /** @@ -576,7 +578,6 @@ public void run(String deviceId, Image image, int sectorSize, throw new TskCoreException("Add image process already started"); } if (!isCanceled) { //with isCanceled being guarded by this it will have the same value everywhere in this synchronized block - //imageHandle = openImage(imageFilePaths, sectorSize, false, caseDbIdentifier); imageHandle = image.getImageHandle(); tskAutoDbPointer = initAddImgNat(dbHelper, timezoneLongToShort(timeZone), addUnallocSpace, skipFatFsOrphans); } @@ -588,6 +589,7 @@ public void run(String deviceId, Image image, int sectorSize, runAddImgNat(tskAutoDbPointer, deviceId, imageHandle, image.getId(), timeZone, imageWriterPath); } } finally { + finishAddImageProcess(); releaseTSKReadLock(); } } @@ -612,58 +614,62 @@ public synchronized void stop() throws TskCoreException { 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 - * that was started by calling AddImageProcess.run. + * This no longer needs to be called. * * @throws TskCoreException if a critical error occurs within the * SleuthKit. + * + * @deprecated No longer necessary */ + @Deprecated public synchronized void revert() throws TskCoreException { - getTSKReadLock(); - 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(); - } + // No-op } /** - * Completes the process of adding an image to the case database - * that was started by calling AddImageProcess.run. + * This no longer needs to be called. Will simply return the + * object ID of the new image. * * @return The object id of the image that was added. * * @throws TskCoreException if a critical error occurs within the * SleuthKit. + * + * @deprecated No longer necessary */ + @Deprecated public synchronized long commit() throws TskCoreException { - getTSKReadLock(); - 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(); - } + return imageId; } /**