diff --git a/bindings/java/src/org/sleuthkit/datamodel/AddDataSourceCallbacks.java b/bindings/java/src/org/sleuthkit/datamodel/AddDataSourceCallbacks.java index e47ecca20f47189b85bcc7fe71b97efb3dbf1a97..86ea60f25b24dc2c658160d7535b3a2c10f55a7f 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/AddDataSourceCallbacks.java +++ b/bindings/java/src/org/sleuthkit/datamodel/AddDataSourceCallbacks.java @@ -25,21 +25,21 @@ * to the ingest pipeline. */ 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; - - /** - * 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; + /** + * 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; + + /** + * 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; } diff --git a/bindings/java/src/org/sleuthkit/datamodel/AddDataSourceCallbacksException.java b/bindings/java/src/org/sleuthkit/datamodel/AddDataSourceCallbacksException.java index 108fd54bc2361c0f1093f57a22b92425c8fc2bf2..51e3796f074382772d217aca105d556760dbeff5 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/AddDataSourceCallbacksException.java +++ b/bindings/java/src/org/sleuthkit/datamodel/AddDataSourceCallbacksException.java @@ -22,31 +22,31 @@ * */ public class AddDataSourceCallbacksException extends TskException { - private static final long serialVersionUID = 123049876L; + private static final long serialVersionUID = 123049876L; - /** - * Default constructor when error message is not available - */ - public AddDataSourceCallbacksException() { - super("No error message available."); - } + /** + * 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 + * + * @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); - } + /** + * 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/JniDbHelper.java b/bindings/java/src/org/sleuthkit/datamodel/JniDbHelper.java index a16fa8aaf095ae3d09d9d68f54a11342d6010ab6..209612cbe74e32b21dfc4176ebe59ce5dc345de3 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/JniDbHelper.java +++ b/bindings/java/src/org/sleuthkit/datamodel/JniDbHelper.java @@ -40,7 +40,7 @@ class JniDbHelper { private final SleuthkitCase caseDb; private CaseDbTransaction trans = null; - AddDataSourceCallbacks addDataSourceCallbacks; + AddDataSourceCallbacks addDataSourceCallbacks; private final Map<Long, Long> fsIdToRootDir = new HashMap<>(); private final Map<Long, TskData.TSK_FS_TYPE_ENUM> fsIdToFsType = new HashMap<>(); @@ -53,12 +53,12 @@ class JniDbHelper { JniDbHelper(SleuthkitCase caseDb) { this.caseDb = caseDb; trans = null; - addDataSourceCallbacks = null; + addDataSourceCallbacks = null; } - - JniDbHelper(SleuthkitCase caseDb, AddDataSourceCallbacks addDataSourceCallbacks) { + + JniDbHelper(SleuthkitCase caseDb, AddDataSourceCallbacks addDataSourceCallbacks) { this.caseDb = caseDb; - this.addDataSourceCallbacks = addDataSourceCallbacks; + this.addDataSourceCallbacks = addDataSourceCallbacks; trans = null; } @@ -126,19 +126,19 @@ long addImageInfo(int type, long ssize, String timezone, beginTransaction(); long objId = caseDb.addImageJNI(TskData.TSK_IMG_TYPE_ENUM.valueOf(type), ssize, size, timezone, md5, sha1, sha256, deviceId, collectionDetails, trans); - for (int i = 0;i < paths.length;i++) { - caseDb.addImageNameJNI(objId, paths[i], i, trans); - } + for (int i = 0;i < paths.length;i++) { + caseDb.addImageNameJNI(objId, paths[i], i, trans); + } commitTransaction(); - - if (addDataSourceCallbacks != null) { - try { - addDataSourceCallbacks.onDataSourceAdded(objId); - } catch (AddDataSourceCallbacksException ex) { - logger.log(Level.SEVERE, "Error adding data source to ingest stream"); - return -1; - } - } + + if (addDataSourceCallbacks != null) { + try { + addDataSourceCallbacks.onDataSourceAdded(objId); + } catch (AddDataSourceCallbacksException ex) { + logger.log(Level.SEVERE, "Error adding data source to ingest stream"); + return -1; + } + } return objId; } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Error adding image to the database", ex); @@ -358,7 +358,7 @@ long addFile(long parentObjId, * @return 0 if successful, -1 if not */ private long addBatchedFilesToDb() { - List<Long> newObjIds = new ArrayList<>(); + List<Long> newObjIds = new ArrayList<>(); try { beginTransaction(); for (FileInfo fileInfo : batchedFiles) { @@ -381,7 +381,7 @@ private long addBatchedFilesToDb() { null, TskData.FileKnown.UNKNOWN, fileInfo.escaped_path, fileInfo.extension, false, trans); - newObjIds.add(objId); + newObjIds.add(objId); // If we're adding the root directory for the file system, cache it if (fileInfo.parentObjId == fileInfo.fsObjId) { @@ -402,57 +402,57 @@ private long addBatchedFilesToDb() { logger.log(Level.SEVERE, "Error adding file to the database - parent object ID: " + computedParentObjId + ", file system object ID: " + fileInfo.fsObjId + ", name: " + fileInfo.name, ex); revertTransaction(); - batchedFiles.clear(); + batchedFiles.clear(); return -1; } } 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; - } - } + + if (addDataSourceCallbacks != null) { + try { + addDataSourceCallbacks.onFilesAdded(newObjIds); + } catch (AddDataSourceCallbacksException ex) { + logger.log(Level.SEVERE, "Error adding files to ingest stream"); + batchedFiles.clear(); + return -1; + } + } } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Error adding batched files to database", ex); revertTransaction(); - batchedFiles.clear(); + batchedFiles.clear(); return -1; } batchedFiles.clear(); return 0; } - - /** - * Look up the parent object ID for a file using the cache or the database. - * - * @param fileInfo The file to find the parent of - * - * @return Parent object ID - * - * @throws TskCoreException - */ - private long getParentObjId(FileInfo fileInfo) throws TskCoreException { - // Remove the final slash from the path unless we're in the root folder - String parentPath = fileInfo.escaped_path; - if(parentPath.endsWith("/") && ! parentPath.equals("/")) { - parentPath = parentPath.substring(0, parentPath.lastIndexOf('/')); - } + + /** + * Look up the parent object ID for a file using the cache or the database. + * + * @param fileInfo The file to find the parent of + * + * @return Parent object ID + * + * @throws TskCoreException + */ + private long getParentObjId(FileInfo fileInfo) throws TskCoreException { + // Remove the final slash from the path unless we're in the root folder + String parentPath = fileInfo.escaped_path; + if(parentPath.endsWith("/") && ! parentPath.equals("/")) { + parentPath = parentPath.substring(0, parentPath.lastIndexOf('/')); + } - // Look up the parent - ParentCacheKey key = new ParentCacheKey(fileInfo.fsObjId, fileInfo.parMetaAddr, fileInfo.parSeq, parentPath); - if (parentDirCache.containsKey(key)) { - return parentDirCache.get(key); - } else { - // The parent wasn't found in the cache so do a database query - java.io.File parentAsFile = new java.io.File(parentPath); - return caseDb.findParentObjIdJNI(fileInfo.parMetaAddr, fileInfo.fsObjId, parentAsFile.getPath(), parentAsFile.getName(), trans); - } - } + // Look up the parent + ParentCacheKey key = new ParentCacheKey(fileInfo.fsObjId, fileInfo.parMetaAddr, fileInfo.parSeq, parentPath); + if (parentDirCache.containsKey(key)) { + return parentDirCache.get(key); + } else { + // The parent wasn't found in the cache so do a database query + java.io.File parentAsFile = new java.io.File(parentPath); + return caseDb.findParentObjIdJNI(fileInfo.parMetaAddr, fileInfo.fsObjId, parentAsFile.getPath(), parentAsFile.getName(), trans); + } + } /** * Add a layout file to the database.