Skip to content
Snippets Groups Projects
Commit d2fbfe15 authored by apriestman's avatar apriestman
Browse files

Addressing code review comments

parent 36cb607e
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
......@@ -18,35 +18,21 @@
*/
package org.sleuthkit.datamodel;
import java.util.List;
/**
*
* Do-nothing version of AddDataSourceCallbacks
*/
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.");
}
public class DefaultAddDataSourceCallbacks implements AddDataSourceCallbacks {
/**
* Create exception containing the error message
*
* @param msg the message
*/
public AddDataSourceCallbacksException(String msg) {
super(msg);
}
@Override
public void onDataSourceAdded(long dataSourceObjectId) {
// Do nothing
}
/**
* 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);
}
@Override
public void onFilesAdded(List<Long> fileObjectIds) {
// Do nothing
}
}
......@@ -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);
......
......@@ -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());
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment