mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-16 17:57:43 +00:00
Code review + bug fixes
This commit is contained in:
parent
10494299e4
commit
d03108c403
@ -26,14 +26,25 @@ import org.sleuthkit.autopsy.coreutils.UNCPathUtilities;
|
|||||||
* This class encapsulates KWS index data.
|
* This class encapsulates KWS index data.
|
||||||
*/
|
*/
|
||||||
final class Index {
|
final class Index {
|
||||||
|
|
||||||
private final String indexPath;
|
private final String indexPath;
|
||||||
private final String schemaVersion;
|
private final String schemaVersion;
|
||||||
private final String solrVersion;
|
private final String solrVersion;
|
||||||
private final String indexName;
|
private final String indexName;
|
||||||
private static final String DEFAULT_CORE_NAME = "text_index"; //NON-NLS
|
private static final String DEFAULT_CORE_NAME = "text_index"; //NON-NLS
|
||||||
private final UNCPathUtilities uncPathUtilities = new UNCPathUtilities();
|
private final UNCPathUtilities uncPathUtilities = new UNCPathUtilities();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a representation of a text index.
|
||||||
|
*
|
||||||
|
* @param indexPath The path to the index.
|
||||||
|
* @param solrVersion The Solr version of the index.
|
||||||
|
* @param schemaVersion The Solr schema version of the index.
|
||||||
|
* @param coreName The core name, may be the empty string or null if
|
||||||
|
* the corename should be generated.
|
||||||
|
* @param caseName The name of the case, ignored if coreName does not
|
||||||
|
* need to be generated.
|
||||||
|
*/
|
||||||
Index(String indexPath, String solrVersion, String schemaVersion, String coreName, String caseName) {
|
Index(String indexPath, String solrVersion, String schemaVersion, String coreName, String caseName) {
|
||||||
this.indexPath = convertPathToUNC(indexPath);
|
this.indexPath = convertPathToUNC(indexPath);
|
||||||
this.solrVersion = solrVersion;
|
this.solrVersion = solrVersion;
|
||||||
@ -44,7 +55,7 @@ final class Index {
|
|||||||
}
|
}
|
||||||
this.indexName = coreName;
|
this.indexName = coreName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create and sanitize a core name.
|
* Create and sanitize a core name.
|
||||||
*
|
*
|
||||||
@ -53,19 +64,20 @@ final class Index {
|
|||||||
* @return The sanitized Solr core name
|
* @return The sanitized Solr core name
|
||||||
*/
|
*/
|
||||||
private String createCoreName(String caseName) {
|
private String createCoreName(String caseName) {
|
||||||
|
String coreName = sanitizeCoreName(caseName);
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
String coreName = caseName + "_" + dateFormat.format(date);
|
return coreName + "_" + dateFormat.format(date);
|
||||||
return sanitizeCoreName(coreName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitizes the case name for Solr cores.
|
* Sanitizes the case name for Solr cores.
|
||||||
*
|
*
|
||||||
* Solr:
|
* Solr:
|
||||||
* http://stackoverflow.com/questions/29977519/what-makes-an-invalid-core-name
|
* http://stackoverflow.com/questions/29977519/what-makes-an-invalid-core-name
|
||||||
* may not be / \ :
|
* may not be / \ : Starting Solr6: core names must consist entirely of
|
||||||
* Starting Solr6: core names must consist entirely of periods, underscores, hyphens, and alphanumerics as well not start with a hyphen. may not contain space characters.
|
* periods, underscores, hyphens, and alphanumerics as well not start with a
|
||||||
|
* hyphen. may not contain space characters.
|
||||||
*
|
*
|
||||||
* @param coreName A candidate core name.
|
* @param coreName A candidate core name.
|
||||||
*
|
*
|
||||||
@ -83,7 +95,7 @@ final class Index {
|
|||||||
|
|
||||||
// Remove spaces / \ : ? ' "
|
// Remove spaces / \ : ? ' "
|
||||||
result = result.replaceAll("[ /?:'\"\\\\]", "_"); //NON-NLS
|
result = result.replaceAll("[ /?:'\"\\\\]", "_"); //NON-NLS
|
||||||
|
|
||||||
// Make it all lowercase
|
// Make it all lowercase
|
||||||
result = result.toLowerCase();
|
result = result.toLowerCase();
|
||||||
|
|
||||||
@ -100,9 +112,6 @@ final class Index {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String convertPathToUNC(String indexDir) {
|
String convertPathToUNC(String indexDir) {
|
||||||
if (uncPathUtilities == null) {
|
|
||||||
return indexDir;
|
|
||||||
}
|
|
||||||
// if we can check for UNC paths, do so, otherwise just return the indexDir
|
// if we can check for UNC paths, do so, otherwise just return the indexDir
|
||||||
String result = uncPathUtilities.mappedDriveToUNC(indexDir);
|
String result = uncPathUtilities.mappedDriveToUNC(indexDir);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
|
@ -184,7 +184,7 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService {
|
|||||||
public void openCaseResources(CaseContext context) throws AutopsyServiceException {
|
public void openCaseResources(CaseContext context) throws AutopsyServiceException {
|
||||||
ProgressIndicator progress = context.getProgressIndicator();
|
ProgressIndicator progress = context.getProgressIndicator();
|
||||||
int totalNumProgressUnits = 8;
|
int totalNumProgressUnits = 8;
|
||||||
int progressUnitsCompleted = 1;
|
int progressUnitsCompleted = 0;
|
||||||
|
|
||||||
List<Index> indexes = new ArrayList<>();
|
List<Index> indexes = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
@ -311,6 +311,7 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService {
|
|||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.log(Level.SEVERE, String.format("Failed to delete %s when upgrade cancelled", newIndexVersionDir), ex);
|
logger.log(Level.SEVERE, String.format("Failed to delete %s when upgrade cancelled", newIndexVersionDir), ex);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add current index to the list of indexes that exist for this case
|
// add current index to the list of indexes that exist for this case
|
||||||
@ -319,6 +320,16 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
// update text index metadata file
|
||||||
|
if (!indexes.isEmpty()) {
|
||||||
|
IndexMetadata indexMetadata = new IndexMetadata(context.getCase().getCaseDirectory(), indexes);
|
||||||
|
}
|
||||||
|
} catch (IndexMetadata.TextIndexMetadataException ex) {
|
||||||
|
throw new AutopsyServiceException("Failed to save Solr core info in text index metadata file", ex);
|
||||||
|
}
|
||||||
|
|
||||||
// open core
|
// open core
|
||||||
try {
|
try {
|
||||||
progress.progress(Bundle.SolrSearch_openCore_msg(), totalNumProgressUnits - 1);
|
progress.progress(Bundle.SolrSearch_openCore_msg(), totalNumProgressUnits - 1);
|
||||||
@ -327,17 +338,6 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService {
|
|||||||
throw new AutopsyServiceException(String.format("Failed to open or create core for %s", context.getCase().getCaseDirectory()), ex);
|
throw new AutopsyServiceException(String.format("Failed to open or create core for %s", context.getCase().getCaseDirectory()), ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
// update text index metadata file
|
|
||||||
if (!indexes.isEmpty()) {
|
|
||||||
// ELTODO REMOVE
|
|
||||||
List<Index> FAKEindexes = new ArrayList<>();
|
|
||||||
IndexMetadata indexMetadata = new IndexMetadata(context.getCase().getCaseDirectory(), FAKEindexes);
|
|
||||||
}
|
|
||||||
} catch (IndexMetadata.TextIndexMetadataException ex) {
|
|
||||||
throw new AutopsyServiceException("Failed to save Solr core info in text index metadata file", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
progress.progress(Bundle.SolrSearch_complete_msg(), totalNumProgressUnits);
|
progress.progress(Bundle.SolrSearch_complete_msg(), totalNumProgressUnits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user