Merge pull request #4416 from dannysmyda/4463-7Zip-Case-Deletion

4463-7Zip Case Deletion fix, NPE from Services, NoClassDefFoundError for FileUtils fix
This commit is contained in:
Richard Cordovano 2018-12-21 15:15:07 -05:00 committed by GitHub
commit 9fb6ffca8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 18 deletions

View File

@ -54,6 +54,9 @@ public class Services implements Closeable {
tagsManager = new TagsManager(caseDb); tagsManager = new TagsManager(caseDb);
services.add(tagsManager); services.add(tagsManager);
//This lookup fails in the functional test code. See JIRA-4571 for details.
//For the time being, the closing of this service at line 108 will be made
//null safe so that the functional tests run with no issues.
keywordSearchService = Lookup.getDefault().lookup(KeywordSearchService.class); keywordSearchService = Lookup.getDefault().lookup(KeywordSearchService.class);
services.add(keywordSearchService); services.add(keywordSearchService);
@ -105,7 +108,9 @@ public class Services implements Closeable {
@Override @Override
public void close() throws IOException { public void close() throws IOException {
for (Closeable service : services) { for (Closeable service : services) {
service.close(); if(service != null) {
service.close();
}
} }
} }

View File

@ -706,6 +706,7 @@ class SevenZipExtractor {
parentAr.addChild(child); parentAr.addChild(child);
depthMap.put(unpackedFile.getId(), child); depthMap.put(unpackedFile.getId(), child);
} }
unpackedFile.close();
} }
} catch (TskCoreException | NoCurrentCaseException e) { } catch (TskCoreException | NoCurrentCaseException e) {

View File

@ -29,6 +29,7 @@ import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.CaseActionException; import org.sleuthkit.autopsy.casemodule.CaseActionException;
import org.sleuthkit.autopsy.casemodule.CaseDetails; import org.sleuthkit.autopsy.casemodule.CaseDetails;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.coreutils.FileUtil;
/** /**
* Class with utility methods for opening and closing cases for functional * Class with utility methods for opening and closing cases for functional
@ -52,13 +53,8 @@ public final class CaseUtils {
*/ */
Path caseDirectoryPath = Paths.get(System.getProperty("java.io.tmpdir"), caseName); Path caseDirectoryPath = Paths.get(System.getProperty("java.io.tmpdir"), caseName);
File caseDirectory = caseDirectoryPath.toFile(); File caseDirectory = caseDirectoryPath.toFile();
if (caseDirectory.exists()) { if(caseDirectory.exists() && !FileUtil.deleteDir(caseDirectory)){
try { Assert.fail(String.format("Failed to delete existing case %s at %s", caseName, caseDirectoryPath));
FileUtils.deleteDirectory(caseDirectory);
} catch (IOException ex) {
Assert.fail(String.format("Failed to delete existing case %s at %s: %s", caseName, caseDirectoryPath, ex.getMessage()));
Exceptions.printStackTrace(ex);
}
} }
/* /*
@ -96,15 +92,8 @@ public final class CaseUtils {
String caseDirectory = currentCase.getCaseDirectory(); String caseDirectory = currentCase.getCaseDirectory();
try { try {
Case.closeCurrentCase(); Case.closeCurrentCase();
if (deleteCase) { if(deleteCase && !FileUtil.deleteDir(new File(caseDirectory))){
/* Assert.fail(String.format("Failed to delete case directory for case %s at %s", caseName, caseDirectory));
* TODO (JIRA-4241): Restore the code to delete the case
* directory when the Image Gallery tool cleans up its drawable
* database connection deterministically, instead of in a
* finalizer. As it is now, case deletion can fail due to an
* open drawable database file handles.
*/
//FileUtils.deleteDirectory(caseDirectory);
} }
} catch (CaseActionException ex) { } catch (CaseActionException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);