mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-10-25 13:30:08 +00:00
Fixed probe cleanup
- Offline probes share bounded directory rescans after concurrent file creation - Cleanup preserves other I/O failures - Symlink targets remain untouched - Probe tests use Mockito to reproduce cleanup races and failure boundaries
This commit is contained in:
1 parent
2e3a41f262
commit
7d8968c45a
5 files changed
+206
-32
No files matched your search
@@ -56,7 +56,6 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class GenerationProbe {
|
||||
private static final List<Throwable> REPORTED = Collections.synchronizedList(new ArrayList<>());
|
||||
@@ -564,7 +563,7 @@ public final class GenerationProbe {
|
||||
}
|
||||
}
|
||||
try {
|
||||
deleteRecursively(workRoot.toPath());
|
||||
ProbeWorkspaceCleanup.deleteRecursively(workRoot.toPath());
|
||||
} catch (Throwable e) {
|
||||
failure = appendFailure(failure, e);
|
||||
}
|
||||
@@ -581,19 +580,6 @@ public final class GenerationProbe {
|
||||
return failure;
|
||||
}
|
||||
|
||||
private static void deleteRecursively(Path root) throws Exception {
|
||||
if (!Files.exists(root)) {
|
||||
return;
|
||||
}
|
||||
List<Path> paths;
|
||||
try (Stream<Path> walk = Files.walk(root)) {
|
||||
paths = walk.sorted(Comparator.reverseOrder()).toList();
|
||||
}
|
||||
for (Path path : paths) {
|
||||
Files.deleteIfExists(path);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Throwable> settleAndDrain() throws InterruptedException {
|
||||
List<Throwable> drained = new ArrayList<>();
|
||||
long quietSince = System.currentTimeMillis();
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package art.arcane.iris.probe;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.DirectoryNotEmptyException;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
|
||||
final class ProbeWorkspaceCleanup {
|
||||
private static final int MAXIMUM_ATTEMPTS = 4;
|
||||
private static final SimpleFileVisitor<Path> DELETE_VISITOR = new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException {
|
||||
Files.deleteIfExists(file);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFileFailed(Path file, IOException failure) throws IOException {
|
||||
if (failure instanceof NoSuchFileException) {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
throw failure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult postVisitDirectory(Path directory, IOException failure) throws IOException {
|
||||
if (failure != null) {
|
||||
throw failure;
|
||||
}
|
||||
Files.deleteIfExists(directory);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
};
|
||||
|
||||
private ProbeWorkspaceCleanup() {
|
||||
}
|
||||
|
||||
static void deleteRecursively(Path root) throws IOException {
|
||||
for (int attempt = 1; ; attempt++) {
|
||||
try {
|
||||
Files.walkFileTree(root, DELETE_VISITOR);
|
||||
return;
|
||||
} catch (DirectoryNotEmptyException failure) {
|
||||
if (attempt == MAXIMUM_ATTEMPTS) {
|
||||
throw failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,6 @@ import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -56,7 +55,6 @@ import java.util.concurrent.ForkJoinTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
final class RealPackProbeSupport {
|
||||
private static final List<Throwable> REPORTED = Collections.synchronizedList(new ArrayList<>());
|
||||
@@ -616,7 +614,7 @@ final class RealPackProbeSupport {
|
||||
if (clone.waitFor() == 0) {
|
||||
return destination;
|
||||
}
|
||||
deleteRecursively(destination.toPath());
|
||||
ProbeWorkspaceCleanup.deleteRecursively(destination.toPath());
|
||||
}
|
||||
Path sourcePath = source.toPath();
|
||||
Files.walkFileTree(sourcePath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
|
||||
@@ -657,26 +655,13 @@ final class RealPackProbeSupport {
|
||||
|
||||
private static Throwable deleteWorkRoot(File workRoot) {
|
||||
try {
|
||||
deleteRecursively(workRoot.toPath());
|
||||
ProbeWorkspaceCleanup.deleteRecursively(workRoot.toPath());
|
||||
return null;
|
||||
} catch (Throwable failure) {
|
||||
return failure;
|
||||
}
|
||||
}
|
||||
|
||||
private static void deleteRecursively(Path root) throws Exception {
|
||||
if (!Files.exists(root)) {
|
||||
return;
|
||||
}
|
||||
List<Path> paths;
|
||||
try (Stream<Path> walk = Files.walk(root)) {
|
||||
paths = walk.sorted(Comparator.reverseOrder()).toList();
|
||||
}
|
||||
for (Path path : paths) {
|
||||
Files.deleteIfExists(path);
|
||||
}
|
||||
}
|
||||
|
||||
private static Throwable appendFailure(Throwable failure, Throwable additional) {
|
||||
if (failure == null) {
|
||||
return additional;
|
||||
|
||||
Reference in new issue
Block a user