From b6789e21e8f5cfe1a707acdb489b84a45b212a54 Mon Sep 17 00:00:00 2001 From: apriestman <apriestman@basistech.com> Date: Fri, 26 Jun 2020 15:30:02 -0400 Subject: [PATCH] Change success/error handling for addImageProcess --- .../sleuthkit/datamodel/Examples/Sample.java | 2 +- .../org/sleuthkit/datamodel/SleuthkitJNI.java | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/bindings/java/src/org/sleuthkit/datamodel/Examples/Sample.java b/bindings/java/src/org/sleuthkit/datamodel/Examples/Sample.java index 01c250498..cb6963fd3 100755 --- a/bindings/java/src/org/sleuthkit/datamodel/Examples/Sample.java +++ b/bindings/java/src/org/sleuthkit/datamodel/Examples/Sample.java @@ -50,7 +50,7 @@ public static void run(String imagePath) { } catch (TskDataException ex) { Logger.getLogger(Sample.class.getName()).log(Level.SEVERE, null, ex); } - process.commit(); + process.finishAddImageProcess(); // 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 ca10fccca..5d72dde5f 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java @@ -557,6 +557,7 @@ public void run(String deviceId, String[] imageFilePaths, int sectorSize, } if (imageHandle != 0) { runAddImgNat(tskAutoDbPointer, deviceId, imageHandle, timeZone, imageWriterPath); + dbHelper.finish(); } } finally { releaseTSKReadLock(); @@ -583,6 +584,42 @@ 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. + * + * @return The object ID of the newly added image + * + * @throws TskCoreException + */ + public synchronized long finishAddImageProcess() throws TskCoreException { + getTSKReadLock(); + try { + if (tskAutoDbPointer == 0) { + throw new TskCoreException("AddImgProcess::finishAddImageProcess: AutoDB pointer is NULL"); + } + + // 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 + long id = finishAddImgNat(tskAutoDbPointer); + tskAutoDbPointer = 0; + + skCase.addDataSourceToHasChildrenMap(); + return id; + } finally { + releaseTSKReadLock(); + } + } /** * Rolls back the process of adding an image to the case database @@ -590,7 +627,9 @@ public synchronized void stop() throws TskCoreException { * * @throws TskCoreException if a critical error occurs within the * SleuthKit. + * @deprecated Use finishAddImageProcess() instead */ + @Deprecated public synchronized void revert() throws TskCoreException { getTSKReadLock(); try { @@ -614,7 +653,9 @@ public synchronized void revert() throws TskCoreException { * * @throws TskCoreException if a critical error occurs within the * SleuthKit. + * @deprecated Use finishAddImageProcess() instead */ + @Deprecated public synchronized long commit() throws TskCoreException { getTSKReadLock(); try { -- GitLab