# HG changeset patch # User Omair Majid # Date 1374868661 14400 # Node ID 169f039b133ee6df6090a4e07f821dbaf6f8ceef # Parent d448210350bf204048483542ff290514080db9aa integration-tests: only delete directories that exist Reviewed-by: vanaltj Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-July/007634.html diff -r d448210350bf -r 169f039b133e integration-tests/src/test/java/com/redhat/thermostat/itest/IntegrationTest.java --- 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()); }