mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-21 21:19:36 -04:00
Only keep peer keys when reusing network stress test directory
This commit is contained in:
parent
6c5c3371e6
commit
f100ef6384
1 changed files with 14 additions and 4 deletions
|
@ -173,20 +173,30 @@ public class NetworkStressTest {
|
||||||
return stressTestDirPath;
|
return stressTestDirPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the test data directory recursively, unless <code>STRESS_TEST_DIR</code> is defined,
|
||||||
|
* in which case peer node keys are kept.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
private void deleteTestDataDirectory() throws IOException {
|
private void deleteTestDataDirectory() throws IOException {
|
||||||
// Based on <https://stackoverflow.com/a/27917071/6239236> by Tomasz Dzięcielewski.
|
// Based on <https://stackoverflow.com/a/27917071/6239236> by Tomasz Dzięcielewski.
|
||||||
if (System.getenv(TEST_DIR_ENVVAR) != null)
|
boolean keep = System.getenv(TEST_DIR_ENVVAR) != null; // do not remove if given explicitly
|
||||||
return; // do not remove if given explicitly
|
|
||||||
Files.walkFileTree(testDataDir, new SimpleFileVisitor<Path>() {
|
Files.walkFileTree(testDataDir, new SimpleFileVisitor<Path>() {
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||||
Files.delete(file);
|
final String fileName = file.getFileName().toString();
|
||||||
|
if (!(keep && (fileName.equals("enc.key") || fileName.equals("sig.key"))))
|
||||||
|
Files.delete(file);
|
||||||
return FileVisitResult.CONTINUE;
|
return FileVisitResult.CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
||||||
Files.delete(dir);
|
// ``dir`` is always a directory, I/O errors may still trigger ``NullPointerException``.
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
if (!(keep && dir.toFile().listFiles().length > 0))
|
||||||
|
Files.delete(dir);
|
||||||
return FileVisitResult.CONTINUE;
|
return FileVisitResult.CONTINUE;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue