Merge pull request #3347 from APriestman/3208_delayDbWrites

3208 delay writing to the database until the end of the ingest pipeline
This commit is contained in:
Richard Cordovano 2017-12-29 13:00:05 -05:00 committed by GitHub
commit 68a2948a39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 58 additions and 36 deletions

View File

@ -21,10 +21,14 @@ package org.sleuthkit.autopsy.ingest;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.logging.Level;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.AbstractFile;
import org.sleuthkit.datamodel.TskCoreException;
/** /**
* This class manages a sequence of file level ingest modules for a data source * This class manages a sequence of file level ingest modules for a data source
@ -136,10 +140,17 @@ final class FileIngestPipeline {
break; break;
} }
} }
file.close();
if (!this.job.isCancelled()) { if (!this.job.isCancelled()) {
// Save any properties that have not already been saved to the database
try{
file.save(Case.getCurrentCase().getSleuthkitCase());
} catch (TskCoreException ex){
Logger.getLogger(FileIngestPipeline.class.getName()).log(Level.SEVERE, "Failed to save data for file " + file.getId(), ex); //NON-NLS
}
IngestManager.getInstance().fireFileIngestDone(file); IngestManager.getInstance().fireFileIngestDone(file);
} }
file.close();
} }
FileIngestPipeline.ingestManager.setIngestTaskProgressCompleted(task); FileIngestPipeline.ingestManager.setIngestTaskProgressCompleted(task);
return errors; return errors;

View File

@ -136,7 +136,7 @@ class MSOfficeEmbeddedContentExtractor {
*/ */
boolean isContentExtractionSupported(AbstractFile abstractFile) { boolean isContentExtractionSupported(AbstractFile abstractFile) {
try { try {
String abstractFileMimeType = fileTypeDetector.getFileType(abstractFile); String abstractFileMimeType = fileTypeDetector.detectFileType(abstractFile);
for (SupportedExtractionFormats s : SupportedExtractionFormats.values()) { for (SupportedExtractionFormats s : SupportedExtractionFormats.values()) {
if (s.toString().equals(abstractFileMimeType)) { if (s.toString().equals(abstractFileMimeType)) {
abstractFileExtractionFormat = s; abstractFileExtractionFormat = s;

View File

@ -142,7 +142,7 @@ class SevenZipExtractor {
*/ */
boolean isSevenZipExtractionSupported(AbstractFile abstractFile) { boolean isSevenZipExtractionSupported(AbstractFile abstractFile) {
try { try {
String abstractFileMimeType = fileTypeDetector.getFileType(abstractFile); String abstractFileMimeType = fileTypeDetector.detectFileType(abstractFile);
for (SupportedArchiveExtractionFormats s : SupportedArchiveExtractionFormats.values()) { for (SupportedArchiveExtractionFormats s : SupportedArchiveExtractionFormats.values()) {
if (s.toString().equals(abstractFileMimeType)) { if (s.toString().equals(abstractFileMimeType)) {
return true; return true;

View File

@ -189,7 +189,7 @@ final class EncryptionDetectionFileIngestModule extends FileIngestModuleAdapter
* Qualify the MIME type. * Qualify the MIME type.
*/ */
try { try {
String mimeType = fileTypeDetector.getFileType(file); String mimeType = fileTypeDetector.detectFileType(file);
if (mimeType != null && mimeType.equals("application/octet-stream")) { if (mimeType != null && mimeType.equals("application/octet-stream")) {
possiblyEncrypted = true; possiblyEncrypted = true;
} }

View File

@ -251,7 +251,7 @@ public final class ExifParserFileIngestModule implements FileIngestModule {
*/ */
private boolean parsableFormat(AbstractFile f) { private boolean parsableFormat(AbstractFile f) {
try { try {
String mimeType = fileTypeDetector.getFileType(f); String mimeType = fileTypeDetector.detectFileType(f);
if (mimeType != null) { if (mimeType != null) {
return supportedMimeTypes.contains(mimeType); return supportedMimeTypes.contains(mimeType);
} else { } else {

View File

@ -170,7 +170,7 @@ public class FileExtMismatchIngestModule implements FileIngestModule {
if (settings.skipFilesWithNoExtension() && currActualExt.isEmpty()) { if (settings.skipFilesWithNoExtension() && currActualExt.isEmpty()) {
return false; return false;
} }
String currActualSigType = detector.getFileType(abstractFile); String currActualSigType = detector.detectFileType(abstractFile);
if (currActualSigType == null) { if (currActualSigType == null) {
return false; return false;
} }

View File

@ -173,11 +173,11 @@ public class FileTypeDetector {
private boolean isDetectableByTika(String mimeType) { private boolean isDetectableByTika(String mimeType) {
return FileTypeDetector.getTikaDetectedTypes().contains(removeOptionalParameter(mimeType)); return FileTypeDetector.getTikaDetectedTypes().contains(removeOptionalParameter(mimeType));
} }
/** /**
* Gets the MIME type of a file, detecting it if it is not already known. If * Gets the MIME type of a file, detecting it if it is not already known. If
* detection is necessary, the result is added to the case database. * detection is necessary, the result is saved to the AbstractFile object
* *
* IMPORTANT: This method should only be called by ingest modules. All other * IMPORTANT: This method should only be called by ingest modules. All other
* clients should call AbstractFile.getMIMEType, and may call * clients should call AbstractFile.getMIMEType, and may call
* FileTypeDetector.detect, if AbstractFile.getMIMEType returns null. * FileTypeDetector.detect, if AbstractFile.getMIMEType returns null.
@ -190,8 +190,8 @@ public class FileTypeDetector {
* @throws TskCoreException if detection is required and there is a problem * @throws TskCoreException if detection is required and there is a problem
* writing the result to the case database. * writing the result to the case database.
*/ */
public String getFileType(AbstractFile file) throws TskCoreException { public String detectFileType(AbstractFile file) throws TskCoreException {
return detect(file, true); return detect(file, false);
} }
/** /**
@ -213,6 +213,9 @@ public class FileTypeDetector {
/** /**
* Detects the MIME type of a file. The result is saved to the case database * Detects the MIME type of a file. The result is saved to the case database
* only if the add to case database flag is set. * only if the add to case database flag is set.
*
* Ingest modules should not set addToCaseDb to true - the ingest process
* handles the database save.
* *
* @param file The file to test. * @param file The file to test.
* @param addToCaseDb Whether the MIME type should be added to the case * @param addToCaseDb Whether the MIME type should be added to the case
@ -323,6 +326,7 @@ public class FileTypeDetector {
Case.getCurrentCase().getSleuthkitCase().setFileMIMEType(file, mimeType); Case.getCurrentCase().getSleuthkitCase().setFileMIMEType(file, mimeType);
} }
file.setMIMEType(mimeType);
return mimeType; return mimeType;
} }
@ -474,7 +478,30 @@ public class FileTypeDetector {
*/ */
@Deprecated @Deprecated
public String detectAndPostToBlackboard(AbstractFile file) throws TskCoreException { public String detectAndPostToBlackboard(AbstractFile file) throws TskCoreException {
return getFileType(file); return detect(file, true);
}
/**
* Gets the MIME type of a file, detecting it if it is not already known. If
* detection is necessary, the result is added to the case database.
*
* IMPORTANT: This method should only be called by ingest modules. All other
* clients should call AbstractFile.getMIMEType, and may call
* FileTypeDetector.detect, if AbstractFile.getMIMEType returns null.
*
* @param file The file.
*
* @return A MIME type name. If file type could not be detected or results
* were uncertain, octet-stream is returned.
*
* @throws TskCoreException if detection is required and there is a problem
* writing the result to the case database.
*
* @deprecated
*/
@Deprecated
public String getFileType(AbstractFile file) throws TskCoreException {
return detect(file, true);
} }
} }

View File

@ -91,7 +91,7 @@ public class FileTypeIdIngestModule implements FileIngestModule {
*/ */
try { try {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
fileTypeDetector.getFileType(file); fileTypeDetector.detect(file);
addToTotals(jobId, (System.currentTimeMillis() - startTime)); addToTotals(jobId, (System.currentTimeMillis() - startTime));
return ProcessResult.OK; return ProcessResult.OK;
} catch (Exception e) { } catch (Exception e) {

View File

@ -176,7 +176,8 @@ public class HashDbIngestModule implements FileIngestModule {
if (md5Hash == null || md5Hash.isEmpty()) { if (md5Hash == null || md5Hash.isEmpty()) {
try { try {
long calcstart = System.currentTimeMillis(); long calcstart = System.currentTimeMillis();
md5Hash = HashUtility.calculateMd5(file); md5Hash = HashUtility.calculateMd5Hash(file);
file.setMd5Hash(md5Hash);
long delta = (System.currentTimeMillis() - calcstart); long delta = (System.currentTimeMillis() - calcstart);
totals.totalCalctime.addAndGet(delta); totals.totalCalctime.addAndGet(delta);
@ -205,20 +206,8 @@ public class HashDbIngestModule implements FileIngestModule {
foundBad = true; foundBad = true;
totals.totalKnownBadCount.incrementAndGet(); totals.totalKnownBadCount.incrementAndGet();
try { file.setKnown(TskData.FileKnown.BAD);
skCase.setKnown(file, TskData.FileKnown.BAD);
} catch (TskException ex) {
logger.log(Level.WARNING, "Couldn't set notable state for file " + name + " - see sleuthkit log for details", ex); //NON-NLS
services.postMessage(IngestMessage.createErrorMessage(
HashLookupModuleFactory.getModuleName(),
NbBundle.getMessage(this.getClass(),
"HashDbIngestModule.hashLookupErrorMsg",
name),
NbBundle.getMessage(this.getClass(),
"HashDbIngestModule.settingKnownBadStateErr",
name)));
ret = ProcessResult.ERROR;
}
String hashSetName = db.getDisplayName(); String hashSetName = db.getDisplayName();
String comment = ""; String comment = "";
@ -262,13 +251,8 @@ public class HashDbIngestModule implements FileIngestModule {
try { try {
long lookupstart = System.currentTimeMillis(); long lookupstart = System.currentTimeMillis();
if (db.lookupMD5Quick(file)) { if (db.lookupMD5Quick(file)) {
try { file.setKnown(TskData.FileKnown.KNOWN);
skCase.setKnown(file, TskData.FileKnown.KNOWN); break;
break;
} catch (TskException ex) {
logger.log(Level.WARNING, "Couldn't set known state for file " + name + " - see sleuthkit log for details", ex); //NON-NLS
ret = ProcessResult.ERROR;
}
} }
long delta = (System.currentTimeMillis() - lookupstart); long delta = (System.currentTimeMillis() - lookupstart);
totals.totalLookuptime.addAndGet(delta); totals.totalLookuptime.addAndGet(delta);

View File

@ -514,7 +514,7 @@ public final class KeywordSearchIngestModule implements FileIngestModule {
if (context.fileIngestIsCancelled()) { if (context.fileIngestIsCancelled()) {
return; return;
} }
fileType = fileTypeDetector.getFileType(aFile); fileType = fileTypeDetector.detectFileType(aFile);
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
logger.log(Level.SEVERE, String.format("Could not detect format using fileTypeDetector for file: %s", aFile), ex); //NON-NLS logger.log(Level.SEVERE, String.format("Could not detect format using fileTypeDetector for file: %s", aFile), ex); //NON-NLS
return; return;