Skip to content
Snippets Groups Projects
Commit 5b102887 authored by apriestman's avatar apriestman
Browse files

Use parent folder ID for findFiles instead of the path

parent c296c766
No related branches found
No related tags found
No related merge requests found
...@@ -5434,7 +5434,7 @@ List<Content> getAbstractFileChildren(Content parent, TSK_DB_FILES_TYPE_ENUM typ ...@@ -5434,7 +5434,7 @@ List<Content> getAbstractFileChildren(Content parent, TSK_DB_FILES_TYPE_ENUM typ
releaseSingleUserCaseReadLock(); releaseSingleUserCaseReadLock();
} }
} }
/** /**
* Returns the list of all AbstractFile Children for a given * Returns the list of all AbstractFile Children for a given
* AbstractFileParent * AbstractFileParent
...@@ -8395,10 +8395,8 @@ private void updateFilePath(CaseDbConnection connection, long objId, String path ...@@ -8395,10 +8395,8 @@ private void updateFilePath(CaseDbConnection connection, long objId, String path
} }
   
/** /**
* Find all files in the data source, by name and parent * Find all files by name and parent
* *
* @param dataSource the dataSource (Image, parent-less VirtualDirectory) to
* search for the given file name
* @param fileName Pattern of the name of the file or directory to match * @param fileName Pattern of the name of the file or directory to match
* (case insensitive, used in LIKE SQL statement). * (case insensitive, used in LIKE SQL statement).
* @param parentFile Object for parent file/directory to find children in * @param parentFile Object for parent file/directory to find children in
...@@ -8409,8 +8407,27 @@ private void updateFilePath(CaseDbConnection connection, long objId, String path ...@@ -8409,8 +8407,27 @@ private void updateFilePath(CaseDbConnection connection, long objId, String path
* *
* @throws org.sleuthkit.datamodel.TskCoreException * @throws org.sleuthkit.datamodel.TskCoreException
*/ */
public List<AbstractFile> findFiles(Content dataSource, String fileName, AbstractFile parentFile) throws TskCoreException { public List<AbstractFile> findFilesInFolder(String fileName, AbstractFile parentFile) throws TskCoreException {
return findFiles(dataSource, fileName, parentFile.getName()); CaseDbConnection connection = null;
ResultSet rs = null;
acquireSingleUserCaseReadLock();
try {
connection = connections.getConnection();
PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.SELECT_FILES_BY_PARENT_AND_NAME);
statement.clearParameters();
long parentId = parentFile.getId();
statement.setLong(1, parentId);
statement.setString(2, fileName);
rs = connection.executeQuery(statement);
return resultSetToAbstractFiles(rs, connection);
} catch (SQLException ex) {
throw new TskCoreException("Error getting AbstractFile children with name=" + fileName + " for Content parent with ID=" + parentFile.getId(), ex);
} finally {
closeResultSet(rs);
closeConnection(connection);
releaseSingleUserCaseReadLock();
}
} }
   
/** /**
...@@ -12433,6 +12450,12 @@ private enum PREPARED_STATEMENT { ...@@ -12433,6 +12450,12 @@ private enum PREPARED_STATEMENT {
+ "ON tsk_objects.obj_id=tsk_files.obj_id " //NON-NLS + "ON tsk_objects.obj_id=tsk_files.obj_id " //NON-NLS
+ "WHERE (tsk_objects.par_obj_id = ? AND tsk_files.type = ? ) " //NON-NLS + "WHERE (tsk_objects.par_obj_id = ? AND tsk_files.type = ? ) " //NON-NLS
+ "ORDER BY tsk_files.dir_type, LOWER(tsk_files.name)"), //NON-NLS + "ORDER BY tsk_files.dir_type, LOWER(tsk_files.name)"), //NON-NLS
SELECT_FILES_BY_PARENT_AND_NAME("SELECT tsk_files.* " //NON-NLS
+ "FROM tsk_objects INNER JOIN tsk_files " //NON-NLS
+ "ON tsk_objects.obj_id=tsk_files.obj_id " //NON-NLS
+ "WHERE (tsk_objects.par_obj_id = ? AND " //NON-NLS
+ "LOWER(tsk_files.name) LIKE LOWER(?) AND LOWER(tsk_files.name) NOT LIKE LOWER('%journal%')) "//NON-NLS
+ "ORDER BY tsk_files.dir_type, LOWER(tsk_files.name)"), //NON-NLS
SELECT_FILE_IDS_BY_PARENT("SELECT tsk_files.obj_id AS obj_id " //NON-NLS SELECT_FILE_IDS_BY_PARENT("SELECT tsk_files.obj_id AS obj_id " //NON-NLS
+ "FROM tsk_objects INNER JOIN tsk_files " //NON-NLS + "FROM tsk_objects INNER JOIN tsk_files " //NON-NLS
+ "ON tsk_objects.obj_id=tsk_files.obj_id " //NON-NLS + "ON tsk_objects.obj_id=tsk_files.obj_id " //NON-NLS
...@@ -14225,6 +14248,28 @@ public Collection<FileSystem> getFileSystems(Image image) { ...@@ -14225,6 +14248,28 @@ public Collection<FileSystem> getFileSystems(Image image) {
return new ArrayList<>(); return new ArrayList<>();
} }
} }
/**
* Find all files in the data source, by name and parent
*
* @param dataSource the dataSource (Image, parent-less VirtualDirectory) to
* search for the given file name
* @param fileName Pattern of the name of the file or directory to match
* (case insensitive, used in LIKE SQL statement).
* @param parentFile Object for parent file/directory to find children in
*
* @return a list of AbstractFile for files/directories whose name matches
* fileName and that were inside a directory described by
* parentFile.
*
* @throws org.sleuthkit.datamodel.TskCoreException
*
* @deprecated Use findFilesInFolder()
*/
@Deprecated
public List<AbstractFile> findFiles(Content dataSource, String fileName, AbstractFile parentFile) throws TskCoreException {
return findFilesInFolder(fileName, parentFile);
}
   
/** /**
* Acquires a write lock, but only if this is a single-user case. Always * Acquires a write lock, but only if this is a single-user case. Always
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment