24 package org.sleuthkit.autopsy.casemodule.services;
 
   26 import java.io.Closeable;
 
   27 import java.io.IOException;
 
   28 import java.util.ArrayList;
 
   29 import java.util.Collection;
 
   30 import java.util.List;
 
   31 import java.util.logging.Level;
 
   32 import org.openide.util.NbBundle;
 
   42 import org.
sleuthkit.datamodel.SleuthkitCase.CaseDbTransaction;
 
   49 import org.apache.commons.lang3.StringUtils;
 
   85     public synchronized List<AbstractFile> 
findFilesByMimeType(Collection<String> mimeTypes) 
throws TskCoreException {
 
   87             throw new TskCoreException(
"File manager has been closed");
 
  104     public synchronized List<AbstractFile> 
findFilesByParentPath(
long dataSourceObjectID, String parentPath) 
throws TskCoreException {
 
  105         if (null == caseDb) {
 
  106             throw new TskCoreException(
"File manager has been closed");
 
  123     public synchronized List<AbstractFile> 
findFilesByMimeType(Content dataSource, Collection<String> mimeTypes) 
throws TskCoreException {
 
  124         if (null == caseDb) {
 
  125             throw new TskCoreException(
"File manager has been closed");
 
  127         return caseDb.findAllFilesWhere(
"data_source_obj_id = " + dataSource.getId() + 
" AND " + 
createFileTypeInCondition(mimeTypes));
 
  138         String types = StringUtils.join(mimeTypes, 
"', '");
 
  139         return "mime_type IN ('" + types + 
"')";
 
  152         return "data_source_obj_id = " + dataSourceObjectID + 
" AND parent_path LIKE '" + parentPath + 
"%'";
 
  167     public synchronized List<AbstractFile> 
findFiles(String fileName) 
throws TskCoreException {
 
  168         if (null == caseDb) {
 
  169             throw new TskCoreException(
"File manager has been closed");
 
  171         List<AbstractFile> result = 
new ArrayList<>();
 
  172         List<Content> dataSources = caseDb.getRootObjects();
 
  173         for (Content dataSource : dataSources) {
 
  174             result.addAll(
findFiles(dataSource, fileName));
 
  195     public synchronized List<AbstractFile> 
findFiles(String fileName, String parentSubString) 
throws TskCoreException {
 
  196         if (null == caseDb) {
 
  197             throw new TskCoreException(
"File manager has been closed");
 
  199         List<AbstractFile> result = 
new ArrayList<>();
 
  200         List<Content> dataSources = caseDb.getRootObjects();
 
  201         for (Content dataSource : dataSources) {
 
  202             result.addAll(
findFiles(dataSource, fileName, parentSubString));
 
  221     public synchronized List<AbstractFile> 
findFiles(String fileName, AbstractFile parent) 
throws TskCoreException {
 
  222         if (null == caseDb) {
 
  223             throw new TskCoreException(
"File manager has been closed");
 
  225         List<AbstractFile> result = 
new ArrayList<>();
 
  226         List<Content> dataSources = caseDb.getRootObjects();
 
  227         for (Content dataSource : dataSources) {
 
  228             result.addAll(
findFiles(dataSource, fileName, parent));
 
  247     public synchronized List<AbstractFile> 
findFiles(Content dataSource, String fileName) 
throws TskCoreException {
 
  248         if (null == caseDb) {
 
  249             throw new TskCoreException(
"File manager has been closed");
 
  251         return caseDb.findFiles(dataSource, fileName);
 
  272     public synchronized List<AbstractFile> 
findFiles(Content dataSource, String fileName, String parentSubString) 
throws TskCoreException {
 
  273         if (null == caseDb) {
 
  274             throw new TskCoreException(
"File manager has been closed");
 
  276         return caseDb.findFiles(dataSource, fileName, parentSubString);
 
  295     public synchronized List<AbstractFile> 
findFiles(Content dataSource, String fileName, AbstractFile parent) 
throws TskCoreException {
 
  296         if (null == caseDb) {
 
  297             throw new TskCoreException(
"File manager has been closed");
 
  299         return findFiles(dataSource, fileName, parent.getName());
 
  318     public synchronized List<AbstractFile> 
openFiles(Content dataSource, String filePath) 
throws TskCoreException {
 
  319         if (null == caseDb) {
 
  320             throw new TskCoreException(
"File manager has been closed");
 
  322         return caseDb.openFiles(dataSource, filePath);
 
  357             long ctime, 
long crtime, 
long atime, 
long mtime,
 
  360             String rederiveDetails, String toolName, String toolVersion, String otherDetails,
 
  361             TskData.EncodingType encodingType) throws TskCoreException {
 
  362         if (null == caseDb) {
 
  363             throw new TskCoreException(
"File manager has been closed");
 
  365         return caseDb.addDerivedFile(fileName, localPath, size,
 
  366                 ctime, crtime, atime, mtime,
 
  367                 isFile, parentObj, rederiveDetails, toolName, toolVersion, otherDetails, encodingType);
 
  402             long ctime, 
long crtime, 
long atime, 
long mtime,
 
  403             boolean isFile, String mimeType,
 
  404             String rederiveDetails, String toolName, String toolVersion, String otherDetails,
 
  405             TskData.EncodingType encodingType) throws TskCoreException {
 
  406         if (null == caseDb) {
 
  407             throw new TskCoreException(
"File manager has been closed");
 
  409         return caseDb.updateDerivedFile(derivedFile, localPath, size,
 
  410                 ctime, crtime, atime, mtime,
 
  411                 isFile, mimeType, rederiveDetails, toolName, toolVersion, otherDetails, encodingType);
 
  425     public synchronized List<LayoutFile> 
addCarvedFiles(CarvingResult carvingResult) 
throws TskCoreException {
 
  426         if (null == caseDb) {
 
  427             throw new TskCoreException(
"File manager has been closed");
 
  429         return caseDb.addCarvedFiles(carvingResult);
 
  474     public synchronized LocalFilesDataSource 
addLocalFilesDataSource(String deviceId, String rootVirtualDirectoryName, String timeZone, List<String> localFilePaths, 
FileAddProgressUpdater progressUpdater) 
throws TskCoreException, TskDataException {
 
  475         if (null == caseDb) {
 
  476             throw new TskCoreException(
"File manager has been closed");
 
  479         CaseDbTransaction trans = null;
 
  481             String rootDirectoryName = rootVirtualDirectoryName;
 
  482             if (rootDirectoryName.isEmpty()) {
 
  490             trans = caseDb.beginTransaction();
 
  491             LocalFilesDataSource dataSource = caseDb.addLocalFilesDataSource(deviceId, rootDirectoryName, timeZone, trans);
 
  492             List<AbstractFile> filesAdded = 
new ArrayList<>();
 
  493             for (java.io.File localFile : localFiles) {
 
  494                 AbstractFile fileAdded = 
addLocalFile(trans, dataSource, localFile, TskData.EncodingType.NONE, progressUpdater);
 
  495                 if (null != fileAdded) {
 
  496                     filesAdded.add(fileAdded);
 
  498                     throw new TskCoreException(NbBundle.getMessage(
this.getClass(), 
"FileManager.addLocalFilesDirs.exception.cantAdd.msg", localFile.getAbsolutePath()));
 
  507             for (AbstractFile fileAdded : filesAdded) {
 
  517                 } 
catch (TskCoreException ex) {
 
  518                     LOGGER.log(Level.SEVERE, 
"Failed to rollback transaction after exception", ex);
 
  538         int localFileDataSourcesCounter = 0;
 
  540             List<VirtualDirectory> localFileDataSources = caseDb.getVirtualDirectoryRoots();
 
  541             for (VirtualDirectory vd : localFileDataSources) {
 
  543                     ++localFileDataSourcesCounter;
 
  547         } 
catch (TskCoreException ex) {
 
  548             throw new TskCoreException(
"Error querying for existing local file data sources with defualt names", ex);
 
  565         List<java.io.File> localFiles = 
new ArrayList<>();
 
  566         for (String path : localFilePaths) {
 
  567             java.io.File localFile = 
new java.io.File(path);
 
  568             if (!localFile.exists() || !localFile.canRead()) {
 
  569                 throw new TskDataException(String.format(
"File at %s does not exist or cannot be read", localFile.getAbsolutePath()));
 
  571             localFiles.add(localFile);
 
  593     private AbstractFile 
addLocalFile(CaseDbTransaction trans, SpecialDirectory parentDirectory, java.io.File localFile,
 
  595         if (localFile.isDirectory()) {
 
  599             LocalDirectory localDirectory = caseDb.addLocalDirectory(parentDirectory.getId(), localFile.getName(), trans);
 
  600             progressUpdater.fileAdded(localDirectory);
 
  605             final java.io.File[] childFiles = localFile.listFiles();
 
  606             if (childFiles != null && childFiles.length > 0) {
 
  607                 for (java.io.File childFile : childFiles) {
 
  608                     addLocalFile(trans, localDirectory, childFile, progressUpdater);
 
  612             return localDirectory;
 
  614             return caseDb.addLocalFile(localFile.getName(), localFile.getAbsolutePath(), localFile.length(),
 
  616                     localFile.isFile(), encodingType, parentDirectory, trans);
 
  628     public synchronized void close() throws IOException {
 
  655         if (null == caseDb) {
 
  656             throw new TskCoreException(
"File manager has been closed");
 
  660         } 
catch (TskDataException ex) {
 
  661             throw new TskCoreException(ex.getLocalizedMessage(), ex);
 
  684     public synchronized LayoutFile 
addCarvedFile(String fileName, 
long fileSize, 
long parentObjId, List<TskFileRange> layout) 
throws TskCoreException {
 
  685         if (null == caseDb) {
 
  686             throw new TskCoreException(
"File manager has been closed");
 
  688         Content parent = caseDb.getContentById(parentObjId);
 
  689         List<CarvingResult.CarvedFile> carvedFiles = 
new ArrayList<>();
 
  690         carvedFiles.add(
new CarvingResult.CarvedFile(fileName, fileSize, layout));
 
  691         List<LayoutFile> layoutFiles = caseDb.addCarvedFiles(
new CarvingResult(parent, carvedFiles));
 
  692         return layoutFiles.get(0);
 
  711     public synchronized List<LayoutFile> 
addCarvedFiles(List<org.sleuthkit.datamodel.CarvedFileContainer> filesToAdd) 
throws TskCoreException {
 
  712         if (null == caseDb) {
 
  713             throw new TskCoreException(
"File manager has been closed");
 
  715         return caseDb.addCarvedFiles(filesToAdd);
 
  752             long ctime, 
long crtime, 
long atime, 
long mtime,
 
  754             AbstractFile parentFile,
 
  755             String rederiveDetails, String toolName, String toolVersion, String otherDetails) 
throws TskCoreException {
 
  756         return addDerivedFile(fileName, localPath, size, ctime, crtime, atime, mtime, isFile, parentFile,
 
  757                 rederiveDetails, toolName, toolVersion, otherDetails, TskData.EncodingType.NONE);
 
  780     private AbstractFile 
addLocalFile(CaseDbTransaction trans, SpecialDirectory parentDirectory, java.io.File localFile, 
FileAddProgressUpdater progressUpdater) 
throws TskCoreException {
 
  781         return addLocalFile(trans, parentDirectory, localFile, TskData.EncodingType.NONE, progressUpdater);
 
synchronized void close()
 
static String createFileTypeInCondition(Collection< String > mimeTypes)
 
synchronized VirtualDirectory addLocalFilesDirs(List< String > localFilePaths, FileAddProgressUpdater progressUpdater)
 
static final Logger LOGGER
 
synchronized LayoutFile addCarvedFile(String fileName, long fileSize, long parentObjId, List< TskFileRange > layout)
 
synchronized List< AbstractFile > findFiles(String fileName, String parentSubString)
 
void fileAdded(AbstractFile newFile)
 
synchronized List< AbstractFile > findFiles(Content dataSource, String fileName)
 
synchronized DerivedFile addDerivedFile(String fileName, String localPath, long size, long ctime, long crtime, long atime, long mtime, boolean isFile, Content parentObj, String rederiveDetails, String toolName, String toolVersion, String otherDetails, TskData.EncodingType encodingType)
 
synchronized DerivedFile addDerivedFile(String fileName, String localPath, long size, long ctime, long crtime, long atime, long mtime, boolean isFile, AbstractFile parentFile, String rederiveDetails, String toolName, String toolVersion, String otherDetails)
 
AbstractFile addLocalFile(CaseDbTransaction trans, SpecialDirectory parentDirectory, java.io.File localFile, FileAddProgressUpdater progressUpdater)
 
synchronized List< AbstractFile > findFilesByMimeType(Collection< String > mimeTypes)
 
synchronized List< LayoutFile > addCarvedFiles(List< org.sleuthkit.datamodel.CarvedFileContainer > filesToAdd)
 
synchronized List< AbstractFile > openFiles(Content dataSource, String filePath)
 
static String createParentPathCondition(long dataSourceObjectID, String parentPath)
 
synchronized LocalFilesDataSource addLocalFilesDataSource(String deviceId, String rootVirtualDirectoryName, String timeZone, List< String > localFilePaths, FileAddProgressUpdater progressUpdater)
 
static synchronized String generateFilesDataSourceName(SleuthkitCase caseDb)
 
synchronized List< AbstractFile > findFilesByMimeType(Content dataSource, Collection< String > mimeTypes)
 
synchronized List< AbstractFile > findFilesByParentPath(long dataSourceObjectID, String parentPath)
 
void fireModuleContentEvent(ModuleContentEvent moduleContentEvent)
 
synchronized List< AbstractFile > findFiles(String fileName)
 
AbstractFile addLocalFile(CaseDbTransaction trans, SpecialDirectory parentDirectory, java.io.File localFile, TskData.EncodingType encodingType, FileAddProgressUpdater progressUpdater)
 
synchronized static Logger getLogger(String name)
 
synchronized List< LayoutFile > addCarvedFiles(CarvingResult carvingResult)
 
FileManager(SleuthkitCase caseDb)
 
synchronized DerivedFile updateDerivedFile(DerivedFile derivedFile, String localPath, long size, long ctime, long crtime, long atime, long mtime, boolean isFile, String mimeType, String rederiveDetails, String toolName, String toolVersion, String otherDetails, TskData.EncodingType encodingType)
 
static final String LOGICAL_FILE_SET_PREFIX
 
synchronized List< AbstractFile > findFiles(Content dataSource, String fileName, String parentSubString)
 
synchronized List< AbstractFile > findFiles(Content dataSource, String fileName, AbstractFile parent)
 
synchronized List< AbstractFile > findFiles(String fileName, AbstractFile parent)
 
List< java.io.File > getFilesAndDirectories(List< String > localFilePaths)
 
static synchronized IngestServices getInstance()