diff --git a/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java b/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java
index 103ea959ec4..5da1c0759be 100644
--- a/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java
+++ b/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java
@@ -74,20 +74,23 @@ public class FileSystemUtils {
return false;
}
- public static boolean deleteRecursively(File[] roots) {
+ /**
+ * Deletes the given files recursively. if deleteRoots is set to true
+ * the given root files will be deleted as well. Otherwise only their content is deleted.
+ */
+ public static boolean deleteRecursively(File[] roots, boolean deleteRoots) {
boolean deleted = true;
for (File root : roots) {
- deleted &= deleteRecursively(root);
+ deleted &= deleteRecursively(root, deleteRoots);
}
return deleted;
}
- public static boolean deleteRecursively(File root) {
- return deleteRecursively(root, true);
- }
-
- private static boolean innerDeleteRecursively(File root) {
- return deleteRecursively(root, true);
+ /**
+ * Deletes the given files recursively including the given roots.
+ */
+ public static boolean deleteRecursively(File... roots) {
+ return deleteRecursively(roots, true);
}
/**
@@ -105,7 +108,7 @@ public class FileSystemUtils {
File[] children = root.listFiles();
if (children != null) {
for (File aChildren : children) {
- innerDeleteRecursively(aChildren);
+ deleteRecursively(aChildren, true);
}
}
}
diff --git a/src/test/java/org/elasticsearch/test/TestCluster.java b/src/test/java/org/elasticsearch/test/TestCluster.java
index 5ca85ad10b0..2e905192927 100644
--- a/src/test/java/org/elasticsearch/test/TestCluster.java
+++ b/src/test/java/org/elasticsearch/test/TestCluster.java
@@ -762,10 +762,11 @@ public final class TestCluster extends ImmutableTestCluster {
private void wipeDataDirectories() {
if (!dataDirToClean.isEmpty()) {
- logger.info("Wipe data directory for all nodes locations: {}", this.dataDirToClean);
+ boolean deleted = false;
try {
- FileSystemUtils.deleteRecursively(dataDirToClean.toArray(new File[dataDirToClean.size()]));
+ deleted = FileSystemUtils.deleteRecursively(dataDirToClean.toArray(new File[dataDirToClean.size()]), false);
} finally {
+ logger.info("Wipe data directory for all nodes locations: {} success: {}", this.dataDirToClean, deleted);
this.dataDirToClean.clear();
}
}