diff --git a/bindings/java/src/org/sleuthkit/datamodel/AddDataSourceCallbacks.java b/bindings/java/src/org/sleuthkit/datamodel/AddDataSourceCallbacks.java index 86ea60f25b24dc2c658160d7535b3a2c10f55a7f..1dd055e71476941eb8d0034c9e9e1fec299b1455 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/AddDataSourceCallbacks.java +++ b/bindings/java/src/org/sleuthkit/datamodel/AddDataSourceCallbacks.java @@ -21,25 +21,20 @@ import java.util.List; /** - * Interface for sending information directly from a data source processors - * to the ingest pipeline. + * Provides callbacks at key points during the process of adding a data source to a case database. */ public interface AddDataSourceCallbacks { /** * Call when the data source has been completely added to the case database. * * @param dataSourceObjectId The object ID of the new data source - * - * @throws AddDataSourceCallbacksException */ - void onDataSourceAdded(long dataSourceObjectId) throws AddDataSourceCallbacksException; + void onDataSourceAdded(long dataSourceObjectId); /** * Call to add a set of file object IDs that are ready for ingest. * * @param fileObjectIds List of file object IDs. - * - * @throws AddDataSourceCallbacksException */ - void onFilesAdded(List<Long> fileObjectIds) throws AddDataSourceCallbacksException; + void onFilesAdded(List<Long> fileObjectIds); } diff --git a/bindings/java/src/org/sleuthkit/datamodel/AddDataSourceCallbacksException.java b/bindings/java/src/org/sleuthkit/datamodel/AddDataSourceCallbacksException.java deleted file mode 100644 index 51e3796f074382772d217aca105d556760dbeff5..0000000000000000000000000000000000000000 --- a/bindings/java/src/org/sleuthkit/datamodel/AddDataSourceCallbacksException.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SleuthKit Java Bindings - * - * Copyright 2020 Basis Technology Corp. - * Contact: carrier <at> sleuthkit <dot> org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.datamodel; - -/** - * - */ -public class AddDataSourceCallbacksException extends TskException { - private static final long serialVersionUID = 123049876L; - - /** - * Default constructor when error message is not available - */ - public AddDataSourceCallbacksException() { - super("No error message available."); - } - - /** - * Create exception containing the error message - * - * @param msg the message - */ - public AddDataSourceCallbacksException(String msg) { - super(msg); - } - - /** - * Create exception containing the error message and cause exception - * - * @param msg the message - * @param ex cause exception - */ - public AddDataSourceCallbacksException(String msg, Exception ex) { - super(msg, ex); - } -} diff --git a/bindings/java/src/org/sleuthkit/datamodel/DefaultAddDataSourceCallbacks.java b/bindings/java/src/org/sleuthkit/datamodel/DefaultAddDataSourceCallbacks.java new file mode 100644 index 0000000000000000000000000000000000000000..920f6079dcb79813f1faaacbdd30eb40988441ac --- /dev/null +++ b/bindings/java/src/org/sleuthkit/datamodel/DefaultAddDataSourceCallbacks.java @@ -0,0 +1,38 @@ +/* + * SleuthKit Java Bindings + * + * Copyright 2020 Basis Technology Corp. + * Contact: carrier <at> sleuthkit <dot> org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.datamodel; + +import java.util.List; + +/** + * Do-nothing version of AddDataSourceCallbacks + */ +public class DefaultAddDataSourceCallbacks implements AddDataSourceCallbacks { + + @Override + public void onDataSourceAdded(long dataSourceObjectId) { + // Do nothing + } + + @Override + public void onFilesAdded(List<Long> fileObjectIds) { + // Do nothing + } + +} diff --git a/bindings/java/src/org/sleuthkit/datamodel/JniDbHelper.java b/bindings/java/src/org/sleuthkit/datamodel/JniDbHelper.java index 209612cbe74e32b21dfc4176ebe59ce5dc345de3..59b257a26bf0e02e817dde177de41ab1e6a9c06a 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/JniDbHelper.java +++ b/bindings/java/src/org/sleuthkit/datamodel/JniDbHelper.java @@ -50,12 +50,6 @@ class JniDbHelper { private final List<FileInfo> batchedFiles = new ArrayList<>(); private final List<LayoutRangeInfo> batchedLayoutRanges = new ArrayList<>(); - JniDbHelper(SleuthkitCase caseDb) { - this.caseDb = caseDb; - trans = null; - addDataSourceCallbacks = null; - } - JniDbHelper(SleuthkitCase caseDb, AddDataSourceCallbacks addDataSourceCallbacks) { this.caseDb = caseDb; this.addDataSourceCallbacks = addDataSourceCallbacks; @@ -132,12 +126,7 @@ long addImageInfo(int type, long ssize, String timezone, commitTransaction(); if (addDataSourceCallbacks != null) { - try { - addDataSourceCallbacks.onDataSourceAdded(objId); - } catch (AddDataSourceCallbacksException ex) { - logger.log(Level.SEVERE, "Error adding data source to ingest stream"); - return -1; - } + addDataSourceCallbacks.onDataSourceAdded(objId); } return objId; } catch (TskCoreException ex) { @@ -409,13 +398,7 @@ private long addBatchedFilesToDb() { commitTransaction(); if (addDataSourceCallbacks != null) { - try { - addDataSourceCallbacks.onFilesAdded(newObjIds); - } catch (AddDataSourceCallbacksException ex) { - logger.log(Level.SEVERE, "Error adding files to ingest stream"); - batchedFiles.clear(); - return -1; - } + addDataSourceCallbacks.onFilesAdded(newObjIds); } } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Error adding batched files to database", ex); diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java index 87d74f91599b3272fde4aa2f55e74913851e9a32..ca10fccca3e7a63440edc703f4025d48d4053a76 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java @@ -424,7 +424,7 @@ void free() throws TskCoreException { * case database. */ long addImageInfo(long deviceObjId, List<String> imageFilePaths, String timeZone, SleuthkitCase skCase) throws TskCoreException { - JniDbHelper dbHelper = new JniDbHelper(skCase); + JniDbHelper dbHelper = new JniDbHelper(skCase, new DefaultAddDataSourceCallbacks()); try { long tskAutoDbPointer = initializeAddImgNat(dbHelper, timezoneLongToShort(timeZone), false, false, false); runOpenAndAddImgNat(tskAutoDbPointer, UUID.randomUUID().toString(), imageFilePaths.toArray(new String[0]), imageFilePaths.size(), timeZone); @@ -515,28 +515,7 @@ private AddImageProcess(String timeZone, boolean addUnallocSpace, boolean skipFa * the process) */ public void run(String deviceId, String[] imageFilePaths, int sectorSize) throws TskCoreException, TskDataException { - dbHelper = new JniDbHelper(skCase); - getTSKReadLock(); - try { - long imageHandle = 0; - synchronized (this) { - if (0 != tskAutoDbPointer) { - 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); - tskAutoDbPointer = initAddImgNat(dbHelper, timezoneLongToShort(timeZone), addUnallocSpace, skipFatFsOrphans); - } - if (0 == tskAutoDbPointer) { - throw new TskCoreException("initAddImgNat returned a NULL TskAutoDb pointer"); - } - } - if (imageHandle != 0) { - runAddImgNat(tskAutoDbPointer, deviceId, imageHandle, timeZone, imageWriterPath); - } - } finally { - releaseTSKReadLock(); - } + run(deviceId, imageFilePaths, sectorSize, new DefaultAddDataSourceCallbacks()); } /**