Merge pull request #1355 from sidheshenator/case_dir_update_embedded_file_extraction_module

module output dir change with change in current case
This commit is contained in:
Richard Cordovano 2015-06-12 13:06:31 -04:00
commit 8844b5a044
3 changed files with 35 additions and 21 deletions

View File

@ -45,17 +45,12 @@ public final class EmbeddedFileExtractorIngestModule implements FileIngestModule
private final IngestServices services = IngestServices.getInstance();
static final String[] SUPPORTED_EXTENSIONS = {"zip", "rar", "arj", "7z", "7zip", "gzip", "gz", "bzip2", "tar", "tgz",}; // "iso"}; NON-NLS
//buffer for checking file headers and signatures
private static final int readHeaderSize = 4;
private static final byte[] fileHeaderBuffer = new byte[readHeaderSize];
private static final int ZIP_SIGNATURE_BE = 0x504B0304;
private IngestJobContext context;
private long jobId;
private final static IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter();
private static final Case currentCase = Case.getCurrentCase();
protected static final String moduleDirRelative = Case.getModulesOutputDirRelPath() + File.separator + EmbeddedFileExtractorModuleFactory.getModuleName(); //relative to the case, to store in db
protected static final String moduleDirAbsolute = currentCase.getModulesOutputDirAbsPath() + File.separator + EmbeddedFileExtractorModuleFactory.getModuleName(); //absolute, to extract to
String moduleDirRelative;
String moduleDirAbsolute;
private boolean archivextraction;
private boolean imageExtraction;
@ -72,14 +67,19 @@ public final class EmbeddedFileExtractorIngestModule implements FileIngestModule
this.context = context;
jobId = context.getJobId();
final Case currentCase = Case.getCurrentCase();
moduleDirRelative = Case.getModulesOutputDirRelPath() + File.separator + EmbeddedFileExtractorModuleFactory.getModuleName(); //relative to the case, to store in db
moduleDirAbsolute = currentCase.getModulesOutputDirAbsPath() + File.separator + EmbeddedFileExtractorModuleFactory.getModuleName(); //absolute, to extract to
// initialize the folder where the embedded files are extracted.
File extractionDirectory = new File(EmbeddedFileExtractorIngestModule.moduleDirAbsolute);
File extractionDirectory = new File(moduleDirAbsolute);
if (!extractionDirectory.exists()) {
try {
extractionDirectory.mkdirs();
} catch (SecurityException ex) {
logger.log(Level.SEVERE, "Error initializing output dir: " + EmbeddedFileExtractorIngestModule.moduleDirAbsolute, ex); //NON-NLS
services.postMessage(IngestMessage.createErrorMessage(EmbeddedFileExtractorModuleFactory.getModuleName(), "Error initializing", "Error initializing output dir: " + EmbeddedFileExtractorIngestModule.moduleDirAbsolute)); //NON-NLS
logger.log(Level.SEVERE, "Error initializing output dir: " + moduleDirAbsolute, ex); //NON-NLS
services.postMessage(IngestMessage.createErrorMessage(EmbeddedFileExtractorModuleFactory.getModuleName(), "Error initializing", "Error initializing output dir: " + moduleDirAbsolute)); //NON-NLS
throw new IngestModuleException(ex.getMessage());
}
}
@ -92,8 +92,8 @@ public final class EmbeddedFileExtractorIngestModule implements FileIngestModule
}
// initialize the extraction modules.
this.archiveExtractor = new SevenZipExtractor(context, fileTypeDetector);
this.imageExtractor = new ImageExtractor(context, fileTypeDetector);
this.archiveExtractor = new SevenZipExtractor(context, fileTypeDetector, moduleDirRelative, moduleDirAbsolute);
this.imageExtractor = new ImageExtractor(context, fileTypeDetector, moduleDirRelative, moduleDirAbsolute);
}
@Override
@ -167,7 +167,7 @@ public final class EmbeddedFileExtractorIngestModule implements FileIngestModule
* @param localRootRelPath relative path to archive, from getUniqueName()
* @return
*/
protected static String getLocalRootAbsPath(String localRootRelPath) {
String getLocalRootAbsPath(String localRootRelPath) {
return moduleDirAbsolute + File.separator + localRootRelPath;
}
}

View File

@ -58,6 +58,9 @@ class ImageExtractor {
private String parentFileName;
private final String UNKNOWN_NAME_PREFIX = "image_";
private final FileTypeDetector fileTypeDetector;
String moduleDirRelative;
String moduleDirAbsolute;
/**
* Enum of mimetypes which support image extraction
*/
@ -84,12 +87,14 @@ class ImageExtractor {
}
private SupportedImageExtractionFormats abstractFileExtractionFormat;
ImageExtractor(IngestJobContext context, FileTypeDetector fileTypeDetector) {
ImageExtractor(IngestJobContext context, FileTypeDetector fileTypeDetector, String moduleDirRelative, String moduleDirAbsolute) {
this.fileManager = Case.getCurrentCase().getServices().getFileManager();
this.services = IngestServices.getInstance();
this.context = context;
this.fileTypeDetector = fileTypeDetector;
this.moduleDirRelative = moduleDirRelative;
this.moduleDirAbsolute = moduleDirAbsolute;
}
/**
@ -481,7 +486,7 @@ class ImageExtractor {
* @return path to the image extraction folder for a given abstract file.
*/
private String getOutputFolderPath(String parentFileName) {
String outputFolderPath = EmbeddedFileExtractorIngestModule.moduleDirAbsolute + File.separator + parentFileName;
String outputFolderPath = moduleDirAbsolute + File.separator + parentFileName;
File outputFilePath = new File(outputFolderPath);
if (!outputFilePath.exists()) {
try {
@ -504,7 +509,7 @@ class ImageExtractor {
*/
private String getFileRelativePath(String fileName) {
// Used explicit FWD slashes to maintain DB consistency across operating systems.
return "/" + EmbeddedFileExtractorIngestModule.moduleDirRelative + "/" + this.parentFileName + "/" + fileName; //NON-NLS
return "/" + moduleDirRelative + "/" + this.parentFileName + "/" + fileName; //NON-NLS
}
/**

View File

@ -79,6 +79,13 @@ class SevenZipExtractor {
private static final long MIN_FREE_DISK_SPACE = 1 * 1000 * 1000000L; //1GB
//counts archive depth
private ArchiveDepthCountTree archiveDepthCountTree;
String moduleDirRelative;
String moduleDirAbsolute;
private String getLocalRootAbsPath(String uniqueArchiveFileName) {
return moduleDirAbsolute + File.separator + uniqueArchiveFileName;
}
/**
* Enum of mimetypes which support archive extraction
*/
@ -103,7 +110,7 @@ class SevenZipExtractor {
// TODO Expand to support more formats after upgrading Tika
}
SevenZipExtractor(IngestJobContext context, FileTypeDetector fileTypeDetector) throws IngestModuleException {
SevenZipExtractor(IngestJobContext context, FileTypeDetector fileTypeDetector, String moduleDirRelative, String moduleDirAbsolute) throws IngestModuleException {
if (!SevenZip.isInitializedSuccessfully() && (SevenZip.getLastInitializationException() == null)) {
try {
SevenZip.initSevenZipFromPlatformJAR();
@ -121,6 +128,8 @@ class SevenZipExtractor {
}
this.context = context;
this.fileTypeDetector = fileTypeDetector;
this.moduleDirRelative = moduleDirRelative;
this.moduleDirAbsolute = moduleDirAbsolute;
this.archiveDepthCountTree = new ArchiveDepthCountTree();
}
@ -308,7 +317,7 @@ class SevenZipExtractor {
//setup the archive local root folder
final String uniqueArchiveFileName = EmbeddedFileExtractorIngestModule.getUniqueName(archiveFile);
final String localRootAbsPath = EmbeddedFileExtractorIngestModule.getLocalRootAbsPath(uniqueArchiveFileName);
final String localRootAbsPath = getLocalRootAbsPath(uniqueArchiveFileName);
final File localRoot = new File(localRootAbsPath);
if (!localRoot.exists()) {
try {
@ -321,7 +330,7 @@ class SevenZipExtractor {
}
//initialize tree hierarchy to keep track of unpacked file structure
SevenZipExtractor.UnpackedTree unpackedTree = new SevenZipExtractor.UnpackedTree(EmbeddedFileExtractorIngestModule.moduleDirRelative + "/" + uniqueArchiveFileName, archiveFile);
SevenZipExtractor.UnpackedTree unpackedTree = new SevenZipExtractor.UnpackedTree(moduleDirRelative + "/" + uniqueArchiveFileName, archiveFile);
long freeDiskSpace = services.getFreeDiskSpace();
@ -420,8 +429,8 @@ class SevenZipExtractor {
final String uniqueExtractedName = uniqueArchiveFileName + File.separator + (item.getItemIndex() / 1000) + File.separator + item.getItemIndex() + new File(pathInArchive).getName();
//final String localRelPath = unpackDir + File.separator + localFileRelPath;
final String localRelPath = EmbeddedFileExtractorIngestModule.moduleDirRelative + File.separator + uniqueExtractedName;
final String localAbsPath = EmbeddedFileExtractorIngestModule.moduleDirAbsolute + File.separator + uniqueExtractedName;
final String localRelPath = moduleDirRelative + File.separator + uniqueExtractedName;
final String localAbsPath = moduleDirAbsolute + File.separator + uniqueExtractedName;
//create local dirs and empty files before extracted
File localFile = new java.io.File(localAbsPath);