More changes to ensure test dirs are clean and errors reported
This commit is contained in:
Jan Bartel 2017-03-23 14:03:06 +11:00
parent b242f1e902
commit 8059b8553b
1 changed files with 37 additions and 17 deletions

View File

@ -29,6 +29,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -498,6 +499,11 @@ public class FileSessionDataStore extends AbstractSessionDataStore
} }
/**
* Remove all existing session files for the session in the context
* @param storeDir where the session files are stored
* @param idInContext the session id within a particular context
*/
private void deleteAllFiles(final File storeDir, final String idInContext) private void deleteAllFiles(final File storeDir, final String idInContext)
{ {
File[] files = storeDir.listFiles (new FilenameFilter() { File[] files = storeDir.listFiles (new FilenameFilter() {
@ -522,7 +528,14 @@ public class FileSessionDataStore extends AbstractSessionDataStore
//delete all files //delete all files
for (File f:files) for (File f:files)
{ {
f.delete(); try
{
Files.deleteIfExists(f.toPath());
}
catch (Exception e)
{
LOG.warn("Unable to delete session file", e);
}
} }
} }
@ -564,6 +577,8 @@ public class FileSessionDataStore extends AbstractSessionDataStore
//delete all but the most recent file //delete all but the most recent file
File file = null; File file = null;
for (File f:files) for (File f:files)
{
try
{ {
if (file == null) if (file == null)
file = f; file = f;
@ -572,15 +587,20 @@ public class FileSessionDataStore extends AbstractSessionDataStore
//accept the newest file //accept the newest file
if (f.lastModified() > file.lastModified()) if (f.lastModified() > file.lastModified())
{ {
file.delete(); Files.deleteIfExists(file.toPath());
file = f; file = f;
} }
else else
{ {
f.delete(); Files.deleteIfExists(f.toPath());
} }
} }
} }
catch (Exception e)
{
LOG.warn("Unable to delete old session file", e);
}
}
return file; return file;
} }