Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorMartin Weber2020-03-21 23:17:22 +0000
committerJonah Graham2020-03-21 23:17:54 +0000
commit268903ba016b97f61dd61278cec6abffc6f667ff (patch)
tree668b873f837e508e263fe97b027f89535c8e7d3c /build
parent6f08d31fe962a79895699b0be7fe9e6d1d19e66e (diff)
downloadorg.eclipse.cdt-268903ba016b97f61dd61278cec6abffc6f667ff.tar.gz
org.eclipse.cdt-268903ba016b97f61dd61278cec6abffc6f667ff.tar.xz
org.eclipse.cdt-268903ba016b97f61dd61278cec6abffc6f667ff.zip
Bug 561318: Recursively delete files without running out of handles
Change-Id: Ib760f53a22bb75f0447c633341728a49cdf8cbfb Signed-off-by: Martin Weber <fifteenknots505@gmail.com>
Diffstat (limited to 'build')
-rw-r--r--build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java26
1 files changed, 21 insertions, 5 deletions
diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java
index b695684af21..31e9d3c8a0f 100644
--- a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java
+++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java
@@ -13,8 +13,11 @@ package org.eclipse.cdt.cmake.core.internal;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
+import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -318,13 +321,26 @@ public class CMakeBuildConfiguration extends CBuildConfiguration {
}
}
- private void cleanDirectory(Path dir) throws IOException {
+ /** Recursively removes any files and directories found in the specified Path.
+ */
+ private static void cleanDirectory(Path dir) throws IOException {
+ SimpleFileVisitor<Path> deltor = new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ Files.delete(file);
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
+ super.postVisitDirectory(dir, exc);
+ Files.delete(dir);
+ return FileVisitResult.CONTINUE;
+ }
+ };
Path[] files = Files.list(dir).toArray(Path[]::new);
for (Path file : files) {
- if (Files.isDirectory(file))
- cleanDirectory(file);
- else
- Files.delete(file);
+ Files.walkFileTree(file, deltor);
}
}

Back to the top