Fix weird race condition

This commit is contained in:
Juuz
2022-01-21 01:00:58 +02:00
parent bd22f11628
commit 7ede01f92e
2 changed files with 8 additions and 6 deletions

View File

@@ -270,11 +270,13 @@ public class MinecraftPatchedProvider extends MergedMinecraftProvider {
Path tmpSrg = getToSrgMappings();
Set<File> mcLibs = getProject().getConfigurations().getByName(Constants.Configurations.MINECRAFT_DEPENDENCIES).resolve();
ThreadingUtils.run(() -> {
Files.copy(SpecialSourceExecutor.produceSrgJar(getExtension().getMcpConfigProvider().getRemapAction(), getProject(), "client", mcLibs, clientJar, tmpSrg), minecraftClientSrgJar.toPath());
}, () -> {
Files.copy(SpecialSourceExecutor.produceSrgJar(getExtension().getMcpConfigProvider().getRemapAction(), getProject(), "server", mcLibs, serverJar, tmpSrg), minecraftServerSrgJar.toPath());
});
// These can't be threaded because accessing getRemapAction().getMainClass() can cause a situation where
// 1. thread A has an FS open
// 2. thread B tries to open a new one, but fails
// 3. thread A closes its FS
// 4. thread B tries to get the already open one => crash
Files.copy(SpecialSourceExecutor.produceSrgJar(getExtension().getMcpConfigProvider().getRemapAction(), getProject(), "client", mcLibs, clientJar, tmpSrg), minecraftClientSrgJar.toPath());
Files.copy(SpecialSourceExecutor.produceSrgJar(getExtension().getMcpConfigProvider().getRemapAction(), getProject(), "server", mcLibs, serverJar, tmpSrg), minecraftServerSrgJar.toPath());
}
private Path getToSrgMappings() throws IOException {

View File

@@ -57,7 +57,7 @@ public class SpecialSourceExecutor {
}
public static Path produceSrgJar(RemapAction remapAction, Project project, String side, Set<File> mcLibs, Path officialJar, Path mappings)
throws Exception {
throws IOException {
Set<String> filter = Files.readAllLines(mappings, StandardCharsets.UTF_8).stream()
.filter(s -> !s.startsWith("\t"))
.map(s -> s.split(" ")[0] + ".class")