diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java index bee2d679eaffed289514354e5dc1730fb16c752e..301a90de03fe6ba28d3d48e99ba264438a5e7c8c 100755 --- a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java @@ -5441,7 +5441,7 @@ List<Content> getAbstractFileChildren(Content parent, TSK_DB_FILES_TYPE_ENUM typ releaseSingleUserCaseReadLock(); } } - + /** * Returns the list of all AbstractFile Children for a given * AbstractFileParent @@ -8405,10 +8405,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 * (case insensitive, used in LIKE SQL statement). * @param parentFile Object for parent file/directory to find children in @@ -8419,8 +8417,27 @@ private void updateFilePath(CaseDbConnection connection, long objId, String path * * @throws org.sleuthkit.datamodel.TskCoreException */ - public List<AbstractFile> findFiles(Content dataSource, String fileName, AbstractFile parentFile) throws TskCoreException { - return findFiles(dataSource, fileName, parentFile.getName()); + public List<AbstractFile> findFilesInFolder(String fileName, AbstractFile parentFile) throws TskCoreException { + 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(); + } } /** @@ -12448,6 +12465,12 @@ private enum PREPARED_STATEMENT { + "ON tsk_objects.obj_id=tsk_files.obj_id " //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 + 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 + "FROM tsk_objects INNER JOIN tsk_files " //NON-NLS + "ON tsk_objects.obj_id=tsk_files.obj_id " //NON-NLS @@ -14236,6 +14259,28 @@ public Collection<FileSystem> getFileSystems(Image image) { 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