mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 01:15:29 +02:00
Bug 561318: Recursively delete files without running out of handles
Change-Id: Ib760f53a22bb75f0447c633341728a49cdf8cbfb Signed-off-by: Martin Weber <fifteenknots505@gmail.com>
This commit is contained in:
parent
6f08d31fe9
commit
268903ba01
1 changed files with 21 additions and 5 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue