Mercurial > hg > release > thermostat-0.15
changeset 1185:169f039b133e
integration-tests: only delete directories that exist
Reviewed-by: vanaltj
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-July/007634.html
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Fri, 26 Jul 2013 15:57:41 -0400 |
parents | d448210350bf |
children | ec20c8c28a0e |
files | integration-tests/src/test/java/com/redhat/thermostat/itest/IntegrationTest.java |
diffstat | 1 files changed, 12 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/integration-tests/src/test/java/com/redhat/thermostat/itest/IntegrationTest.java Fri Jul 26 12:29:07 2013 -0400 +++ b/integration-tests/src/test/java/com/redhat/thermostat/itest/IntegrationTest.java Fri Jul 26 15:57:41 2013 -0400 @@ -110,8 +110,14 @@ } public static void clearStorageDataDirectory() throws IOException { - String storageDir = getStorageDataDirectory(); - deleteFilesRecursivelyUnder(storageDir); + File storageDir = new File(getStorageDataDirectory()); + if (storageDir.exists()) { + if (storageDir.isDirectory()) { + deleteFilesRecursivelyUnder(storageDir); + } else { + throw new IllegalStateException(storageDir + " exists but is not a directory"); + } + } } public static Process runThermostat(String... args) throws IOException { @@ -240,18 +246,17 @@ return (int) pidField.get(process); } - private static void deleteFilesRecursivelyUnder(String path) throws IOException { - File directory = new File(path); - if (!directory.isDirectory()) { + private static void deleteFilesRecursivelyUnder(File path) throws IOException { + if (!path.isDirectory()) { throw new IOException("Cannot delete files under a non-directory: " + path); } - File[] filesToDelete = directory.listFiles(); + File[] filesToDelete = path.listFiles(); if (filesToDelete == null) { throw new IOException("Error getting directory listing: " + path); } for (File theFile : filesToDelete) { if (theFile.isDirectory()) { - deleteFilesRecursivelyUnder(theFile.getCanonicalPath()); + deleteFilesRecursivelyUnder(theFile); } Files.deleteIfExists(theFile.toPath()); }