Skip to content

Commit

Permalink
recursively delete game directory
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Jan 1, 2025
1 parent a609367 commit 3bd7fd9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion junit/src/main/java/net/neoforged/fml/junit/JUnitService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

import java.io.IOException;
import java.io.UncheckedIOException;
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.List;
import java.util.ServiceLoader;
import java.util.Set;
Expand Down Expand Up @@ -69,7 +72,19 @@ public void launcherSessionClosed(LauncherSession session) {

if (gameDir != null) {
try {
Files.deleteIfExists(gameDir);
Files.walkFileTree(gameDir, new SimpleFileVisitor<>() {
@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 {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
throw new UncheckedIOException("Failed to delete temporary game directory", e);
}
Expand Down

0 comments on commit 3bd7fd9

Please sign in to comment.