remove cached references to FileTypesByMimeType

This commit is contained in:
Greg DiCristofaro 2021-04-27 11:38:40 -04:00
parent 5796ef4c6c
commit 76dfccad02
4 changed files with 25 additions and 29 deletions

View File

@ -34,6 +34,8 @@ import org.openide.nodes.Sheet;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.lookup.Lookups;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.AnalysisResult;
import org.sleuthkit.datamodel.AnalysisResultAdded;
@ -76,16 +78,10 @@ public final class FileTypes implements AutopsyVisitableItem {
*/
private boolean showCounts = true;
private final SleuthkitCase skCase;
private final long datasourceObjId;
FileTypes(SleuthkitCase skCase) {
this(skCase, 0);
}
FileTypes(SleuthkitCase skCase, long dsObjId) {
this.skCase = skCase;
FileTypes(long dsObjId) {
this.datasourceObjId = dsObjId;
updateShowCounts();
}
@ -95,10 +91,6 @@ public final class FileTypes implements AutopsyVisitableItem {
return visitor.visit(this);
}
SleuthkitCase getSleuthkitCase() {
return skCase;
}
long filteringDataSourceObjId() {
return this.datasourceObjId;
}
@ -112,10 +104,10 @@ public final class FileTypes implements AutopsyVisitableItem {
*/
if (showCounts) {
try {
if (skCase.countFilesWhere("1=1") > NODE_COUNT_FILE_TABLE_THRESHOLD) { //NON-NLS
if (Case.getCurrentCaseThrows().getSleuthkitCase().countFilesWhere("1=1") > NODE_COUNT_FILE_TABLE_THRESHOLD) { //NON-NLS
showCounts = false;
}
} catch (TskCoreException tskCoreException) {
} catch (NoCurrentCaseException | TskCoreException tskCoreException) {
showCounts = false;
logger.log(Level.SEVERE, "Error counting files.", tskCoreException); //NON-NLS
}

View File

@ -34,6 +34,7 @@ import org.openide.nodes.ChildFactory;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.nodes.Sheet;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages;
import org.openide.util.lookup.Lookups;
@ -58,16 +59,18 @@ public final class FileTypesByExtension implements AutopsyVisitableItem {
private final static Logger logger = Logger.getLogger(FileTypesByExtension.class.getName());
private static final Set<IngestManager.IngestJobEvent> INGEST_JOB_EVENTS_OF_INTEREST = EnumSet.of(IngestManager.IngestJobEvent.COMPLETED, IngestManager.IngestJobEvent.CANCELLED);
private static final Set<IngestManager.IngestModuleEvent> INGEST_MODULE_EVENTS_OF_INTEREST = EnumSet.of(IngestManager.IngestModuleEvent.CONTENT_CHANGED);
private final SleuthkitCase skCase;
private final FileTypes typesRoot;
public FileTypesByExtension(FileTypes typesRoot) {
this.skCase = typesRoot.getSleuthkitCase();
this.typesRoot = typesRoot;
}
public SleuthkitCase getSleuthkitCase() {
return this.skCase;
try {
return Case.getCurrentCaseThrows().getSleuthkitCase();
} catch (NoCurrentCaseException ex) {
return null;
}
}
@Override
@ -404,7 +407,11 @@ public final class FileTypesByExtension implements AutopsyVisitableItem {
@Override
long calculateChildCount() throws TskCoreException {
return skCase.countFilesWhere(createQuery(filter));
try {
return Case.getCurrentCaseThrows().getSleuthkitCase().countFilesWhere(createQuery(filter));
} catch (NoCurrentCaseException ex) {
throw new TskCoreException("No open case.", ex);
}
}
}

View File

@ -63,7 +63,7 @@ public final class FileTypesByMimeType extends Observable implements AutopsyVisi
private final static Logger logger = Logger.getLogger(FileTypesByMimeType.class.getName());
private static final Set<IngestManager.IngestJobEvent> INGEST_JOB_EVENTS_OF_INTEREST = EnumSet.of(IngestManager.IngestJobEvent.COMPLETED, IngestManager.IngestJobEvent.CANCELLED);
private final SleuthkitCase skCase;
/**
* The nodes of this tree will be determined dynamically by the mimetypes
* which exist in the database. This hashmap will store them with the media
@ -130,11 +130,8 @@ public final class FileTypesByMimeType extends Observable implements AutopsyVisi
+ " GROUP BY mime_type";
synchronized (existingMimeTypeCounts) {
existingMimeTypeCounts.clear();
if (skCase == null) {
return;
}
try (SleuthkitCase.CaseDbQuery dbQuery = skCase.executeQuery(query)) {
try
(SleuthkitCase.CaseDbQuery dbQuery = Case.getCurrentCaseThrows().getSleuthkitCase().executeQuery(query)) {
ResultSet resultSet = dbQuery.getResultSet();
while (resultSet.next()) {
final String mime_type = resultSet.getString("mime_type"); //NON-NLS
@ -149,7 +146,7 @@ public final class FileTypesByMimeType extends Observable implements AutopsyVisi
}
}
}
} catch (TskCoreException | SQLException ex) {
} catch (NoCurrentCaseException | TskCoreException | SQLException ex) {
logger.log(Level.SEVERE, "Unable to populate File Types by MIME Type tree view from DB: ", ex); //NON-NLS
}
}
@ -159,7 +156,6 @@ public final class FileTypesByMimeType extends Observable implements AutopsyVisi
}
FileTypesByMimeType(FileTypes typesRoot) {
this.skCase = typesRoot.getSleuthkitCase();
this.typesRoot = typesRoot;
this.pcl = (PropertyChangeEvent evt) -> {
String eventType = evt.getPropertyName();
@ -497,9 +493,10 @@ public final class FileTypesByMimeType extends Observable implements AutopsyVisi
@Override
protected List<FileTypesKey> makeKeys() {
try {
return skCase.findAllFilesWhere(createBaseWhereExpr() + " AND mime_type = '" + mimeType + "'")
return Case.getCurrentCaseThrows().getSleuthkitCase()
.findAllFilesWhere(createBaseWhereExpr() + " AND mime_type = '" + mimeType + "'")
.stream().map(f -> new FileTypesKey(f)).collect(Collectors.toList()); //NON-NLS
} catch (TskCoreException ex) {
} catch (NoCurrentCaseException | TskCoreException ex) {
logger.log(Level.SEVERE, "Couldn't get search results", ex); //NON-NLS
}
return Collections.emptyList();

View File

@ -41,7 +41,7 @@ public class ViewsNode extends DisplayableItemNode {
super(
new RootContentChildren(Arrays.asList(
new FileTypes(sleuthkitCase, dsObjId),
new FileTypes(dsObjId),
// June '15: Recent Files was removed because it was not useful w/out filtering
// add it back in if we can filter the results to a more managable size.
// new RecentFiles(sleuthkitCase),