Merge pull request #3384 from rcordovano/release-4.6.0

Add write type side effect to FileTypeDetector.getMIMEType
This commit is contained in:
Richard Cordovano
2018-01-23 11:18:40 -05:00
committed by GitHub
13 changed files with 25 additions and 19 deletions
@@ -151,7 +151,7 @@ public abstract class MediaViewVideoPanel extends JPanel implements FrameCapture
if (AUDIO_EXTENSIONS.contains("." + extension) || getExtensionsList().contains("." + extension)) {
SortedSet<String> mimeTypes = new TreeSet<>(getMimeTypes());
try {
String mimeType = new FileTypeDetector().detectMIMEType(file);
String mimeType = new FileTypeDetector().getMIMEType(file);
return mimeTypes.contains(mimeType);
} catch (FileTypeDetector.FileTypeDetectorInitException ex) {
logger.log(Level.WARNING, "Failed to look up mimetype for " + file.getName() + " using FileTypeDetector. Fallingback on AbstractFile.isMimeType", ex);
@@ -263,7 +263,7 @@ public class ImageUtils {
return true;
} else {
try {
String mimeType = getFileTypeDetector().detectMIMEType(file);
String mimeType = getFileTypeDetector().getMIMEType(file);
if (StringUtils.isNotBlank(mimeTypePrefix) && mimeType.startsWith(mimeTypePrefix)) {
return true;
}
@@ -135,7 +135,7 @@ class MSOfficeEmbeddedContentExtractor {
* supported. Else it returns false.
*/
boolean isContentExtractionSupported(AbstractFile abstractFile) {
String abstractFileMimeType = fileTypeDetector.detectMIMEType(abstractFile);
String abstractFileMimeType = fileTypeDetector.getMIMEType(abstractFile);
for (SupportedExtractionFormats s : SupportedExtractionFormats.values()) {
if (s.toString().equals(abstractFileMimeType)) {
abstractFileExtractionFormat = s;
@@ -139,7 +139,7 @@ class SevenZipExtractor {
* supported. Else it returns false.
*/
boolean isSevenZipExtractionSupported(AbstractFile abstractFile) {
String abstractFileMimeType = fileTypeDetector.detectMIMEType(abstractFile);
String abstractFileMimeType = fileTypeDetector.getMIMEType(abstractFile);
for (SupportedArchiveExtractionFormats s : SupportedArchiveExtractionFormats.values()) {
if (s.toString().equals(abstractFileMimeType)) {
return true;
@@ -187,7 +187,7 @@ final class EncryptionDetectionFileIngestModule extends FileIngestModuleAdapter
/*
* Qualify the MIME type.
*/
String mimeType = fileTypeDetector.detectMIMEType(file);
String mimeType = fileTypeDetector.getMIMEType(file);
if (mimeType.equals("application/octet-stream")) {
possiblyEncrypted = true;
}
@@ -250,7 +250,7 @@ public final class ExifParserFileIngestModule implements FileIngestModule {
* @return true if to be processed
*/
private boolean parsableFormat(AbstractFile f) {
String mimeType = fileTypeDetector.detectMIMEType(f);
String mimeType = fileTypeDetector.getMIMEType(f);
return supportedMimeTypes.contains(mimeType);
}
@@ -169,7 +169,7 @@ public class FileExtMismatchIngestModule implements FileIngestModule {
if (settings.skipFilesWithNoExtension() && currActualExt.isEmpty()) {
return false;
}
String currActualSigType = detector.detectMIMEType(abstractFile);
String currActualSigType = detector.getMIMEType(abstractFile);
if (settings.getCheckType() != CHECK_TYPE.ALL) {
if (settings.getCheckType() == CHECK_TYPE.NO_TEXT_FILES) {
if (!currActualExt.isEmpty() && currActualSigType.equals("text/plain")) { //NON-NLS
@@ -171,14 +171,15 @@ public class FileTypeDetector {
}
/**
* Detects the MIME type of a file.
* Detects the MIME type of a file, then writes it the AbstractFile object
* representing the file and returns the detected type.
*
* @param file The file to test.
*
* @return A MIME type name. If file type could not be detected, or results
* were uncertain, octet-stream is returned.
*/
public String detectMIMEType(AbstractFile file) {
public String getMIMEType(AbstractFile file) {
/*
* Check to see if the file has already been typed.
*/
@@ -250,6 +251,11 @@ public class FileTypeDetector {
}
}
/*
* Documented side effect: write the result to the AbstractFile object.
*/
file.setMIMEType(mimeType);
return mimeType;
}
@@ -293,7 +299,7 @@ public class FileTypeDetector {
attributes.add(setNameAttribute);
BlackboardAttribute ruleNameAttribute = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY, FileTypeIdModuleFactory.getModuleName(), fileType.getMimeType());
attributes.add(ruleNameAttribute);
artifact.addAttributes(attributes);
artifact.addAttributes(attributes);
try {
Case.getCurrentCase().getServices().getBlackboard().indexArtifact(artifact);
} catch (Blackboard.BlackboardException ex) {
@@ -393,7 +399,7 @@ public class FileTypeDetector {
*/
@Deprecated
public String detectAndPostToBlackboard(AbstractFile file) throws TskCoreException {
String fileType = detectMIMEType(file);
String fileType = getMIMEType(file);
file.setMIMEType(fileType);
file.save();
return fileType;
@@ -417,7 +423,7 @@ public class FileTypeDetector {
*/
@Deprecated
public String getFileType(AbstractFile file) throws TskCoreException {
String fileType = detectMIMEType(file);
String fileType = getMIMEType(file);
file.setMIMEType(fileType);
file.save();
return fileType;
@@ -437,7 +443,7 @@ public class FileTypeDetector {
*/
@Deprecated
public String detect(AbstractFile file) throws TskCoreException {
String fileType = detectMIMEType(file);
String fileType = getMIMEType(file);
return fileType;
}
@@ -91,7 +91,7 @@ public class FileTypeIdIngestModule implements FileIngestModule {
*/
try {
long startTime = System.currentTimeMillis();
file.setMIMEType(fileTypeDetector.detectMIMEType(file));
fileTypeDetector.getMIMEType(file);
addToTotals(jobId, (System.currentTimeMillis() - startTime));
return ProcessResult.OK;
} catch (Exception e) {
@@ -220,7 +220,7 @@ public enum FileTypeUtils {
* mimetype could not be detected.
*/
static boolean hasDrawableMIMEType(AbstractFile file) throws FileTypeDetector.FileTypeDetectorInitException {
String mimeType = getFileTypeDetector().detectMIMEType(file).toLowerCase();
String mimeType = getFileTypeDetector().getMIMEType(file).toLowerCase();
return isDrawableMimeType(mimeType) || (mimeType.equals("audio/x-aiff") && "tiff".equalsIgnoreCase(file.getNameExtension()));
}
@@ -235,7 +235,7 @@ public enum FileTypeUtils {
*/
public static boolean hasVideoMIMEType(AbstractFile file) {
try {
String mimeType = getFileTypeDetector().detectMIMEType(file).toLowerCase();
String mimeType = getFileTypeDetector().getMIMEType(file).toLowerCase();
return mimeType.startsWith("video/") || videoMimeTypes.contains(mimeType);
} catch (FileTypeDetector.FileTypeDetectorInitException ex) {
LOGGER.log(Level.SEVERE, "Error determining MIME type of " + getContentPathSafe(file), ex);
@@ -511,7 +511,7 @@ public final class KeywordSearchIngestModule implements FileIngestModule {
if (context.fileIngestIsCancelled()) {
return;
}
String fileType = fileTypeDetector.detectMIMEType(aFile);
String fileType = fileTypeDetector.getMIMEType(aFile);
// we skip archive formats that are opened by the archive module.
// @@@ We could have a check here to see if the archive module was enabled though...
@@ -1,5 +1,5 @@
#Updated by build script
#Fri, 05 Jan 2018 10:31:22 -0500
#Tue, 23 Jan 2018 11:13:26 -0500
LBL_splash_window_title=Starting Autopsy
SPLASH_HEIGHT=314
SPLASH_WIDTH=538
@@ -1,4 +1,4 @@
#Updated by build script
#Fri, 05 Jan 2018 10:31:22 -0500
#Tue, 23 Jan 2018 11:13:26 -0500
CTL_MainWindow_Title=Autopsy 4.5.0
CTL_MainWindow_Title_No_Project=Autopsy 4.5.0