mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-09 14:49:32 +00:00
Updated Services and FileManager to implement the java.io.Closeable
interface and updated FileManager to throw TskCoreException when its API is used after it has been closed. Closing is propagated to all services when the Case object is closed. These changes are in support of AUT-613.
This commit is contained in:
parent
3824f90a0e
commit
0949fb13d1
@ -360,6 +360,7 @@ public class Case {
|
|||||||
try {
|
try {
|
||||||
this.xmlcm.close(); // close the xmlcm
|
this.xmlcm.close(); // close the xmlcm
|
||||||
this.db.close();
|
this.db.close();
|
||||||
|
services.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CaseActionException("Error while trying to close the current case.", e);
|
throw new CaseActionException("Error while trying to close the current case.", e);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.casemodule.services;
|
package org.sleuthkit.autopsy.casemodule.services;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.sleuthkit.datamodel.FsContent;
|
import org.sleuthkit.datamodel.FsContent;
|
||||||
import org.sleuthkit.datamodel.SleuthkitCase;
|
import org.sleuthkit.datamodel.SleuthkitCase;
|
||||||
@ -12,7 +15,7 @@ import org.sleuthkit.datamodel.TskCoreException;
|
|||||||
/**
|
/**
|
||||||
* Abstraction to facilitate access to files and directories.
|
* Abstraction to facilitate access to files and directories.
|
||||||
*/
|
*/
|
||||||
public class FileManager {
|
public class FileManager implements Closeable {
|
||||||
|
|
||||||
private SleuthkitCase tskCase;
|
private SleuthkitCase tskCase;
|
||||||
|
|
||||||
@ -26,7 +29,10 @@ public class FileManager {
|
|||||||
* given fileName
|
* given fileName
|
||||||
*/
|
*/
|
||||||
public List<FsContent> findFiles(String fileName) throws TskCoreException {
|
public List<FsContent> findFiles(String fileName) throws TskCoreException {
|
||||||
return tskCase.findFiles(fileName);
|
if (tskCase == null) {
|
||||||
|
throw new TskCoreException("Attemtped to use FileManager after it was closed.");
|
||||||
|
}
|
||||||
|
return tskCase.findFiles(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,7 +42,10 @@ public class FileManager {
|
|||||||
* fileName and whose parent directory contains dirName.
|
* fileName and whose parent directory contains dirName.
|
||||||
*/
|
*/
|
||||||
public List<FsContent> findFiles(String fileName, String dirName) throws TskCoreException {
|
public List<FsContent> findFiles(String fileName, String dirName) throws TskCoreException {
|
||||||
return tskCase.findFiles(fileName, dirName);
|
if (tskCase == null) {
|
||||||
|
throw new TskCoreException("Attemtped to use FileManager after it was closed.");
|
||||||
|
}
|
||||||
|
return tskCase.findFiles(fileName, dirName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,7 +55,10 @@ public class FileManager {
|
|||||||
* fileName and that were inside a directory described by parentFsContent.
|
* fileName and that were inside a directory described by parentFsContent.
|
||||||
*/
|
*/
|
||||||
public List<FsContent> findFiles(String fileName, FsContent parentFsContent) throws TskCoreException {
|
public List<FsContent> findFiles(String fileName, FsContent parentFsContent) throws TskCoreException {
|
||||||
return findFiles(fileName, parentFsContent.getName());
|
if (tskCase == null) {
|
||||||
|
throw new TskCoreException("Attemtped to use FileManager after it was closed.");
|
||||||
|
}
|
||||||
|
return findFiles(fileName, parentFsContent.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,7 +67,15 @@ public class FileManager {
|
|||||||
* @return a list of FsContent that have the given file path.
|
* @return a list of FsContent that have the given file path.
|
||||||
*/
|
*/
|
||||||
public List<FsContent> openFiles(String filePath) throws TskCoreException {
|
public List<FsContent> openFiles(String filePath) throws TskCoreException {
|
||||||
return tskCase.openFiles(filePath);
|
if (tskCase == null) {
|
||||||
|
throw new TskCoreException("Attemtped to use FileManager after it was closed.");
|
||||||
|
}
|
||||||
|
return tskCase.openFiles(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
tskCase = null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,25 @@
|
|||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.casemodule.services;
|
package org.sleuthkit.autopsy.casemodule.services;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import org.sleuthkit.datamodel.SleuthkitCase;
|
import org.sleuthkit.datamodel.SleuthkitCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author mciver
|
* @author mciver
|
||||||
*/
|
*/
|
||||||
public class Services {
|
public class Services implements Closeable {
|
||||||
|
|
||||||
private SleuthkitCase tskCase;
|
private SleuthkitCase tskCase;
|
||||||
|
|
||||||
|
// NOTE: all new services added to Services class must be added to this list
|
||||||
|
// of services.
|
||||||
|
List<Closeable> services = new ArrayList<Closeable>();
|
||||||
|
|
||||||
|
// services
|
||||||
private FileManager fileManager;
|
private FileManager fileManager;
|
||||||
|
|
||||||
public Services(SleuthkitCase tskCase) {
|
public Services(SleuthkitCase tskCase) {
|
||||||
@ -22,7 +32,16 @@ public class Services {
|
|||||||
public FileManager getFileManager() {
|
public FileManager getFileManager() {
|
||||||
if (fileManager == null) {
|
if (fileManager == null) {
|
||||||
fileManager = new FileManager(tskCase);
|
fileManager = new FileManager(tskCase);
|
||||||
|
services.add(fileManager);
|
||||||
}
|
}
|
||||||
return fileManager;
|
return fileManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
// close all services
|
||||||
|
for (Closeable service : services) {
|
||||||
|
service.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user