Compare commits

...

3 Commits

Author SHA1 Message Date
Johannes Frohnmeyer 0bd675fc7c
fix: prevent endlessly recursive serialization due to misinterpretation of checked method as getter
ci/woodpecker/push/woodpecker Pipeline failed Details
ci/woodpecker/push/docs Pipeline was successful Details
2023-10-03 20:16:00 +02:00
Johannes Frohnmeyer bcd4e34f7a
fix: defensively use deleteIfExists to prevent races in Instance 2023-10-03 20:15:11 +02:00
Johannes Frohnmeyer 7a7d009e29
fix: use proper dir in ModrinthImporter 2023-10-03 20:14:41 +02:00
3 changed files with 13 additions and 9 deletions

View File

@ -1,5 +1,6 @@
package io.gitlab.jfronny.inceptum.launcher.model.inceptum;
import io.gitlab.jfronny.gson.compile.annotations.GPrefer;
import io.gitlab.jfronny.gson.compile.annotations.GSerializable;
import io.gitlab.jfronny.inceptum.common.GsonPreset;
@ -39,18 +40,21 @@ public class InstanceMeta {
}
public void checkArguments() {
arguments = arguments == null ? Arguments.EMPTY : arguments.checked();
arguments = Arguments.checked(arguments);
}
@GSerializable(configure = GsonPreset.Config.class)
public record Arguments(List<String> jvm, List<String> client, List<String> server) {
public static final Arguments EMPTY = new Arguments(List.of(), List.of(), List.of());
public Arguments checked() {
@GPrefer public Arguments {}
public static Arguments checked(Arguments of) {
if (of == null) return EMPTY;
return new Arguments(
jvm == null ? List.of() : jvm,
client == null ? List.of() : client,
server == null ? List.of() : server
of.jvm == null ? List.of() : of.jvm,
of.client == null ? List.of() : of.client,
of.server == null ? List.of() : of.server
);
}

View File

@ -42,8 +42,8 @@ public class ModrinthImporter extends Importer<ModrinthModpackManifest> {
protected void downloadMods(ModrinthModpackManifest manifest, Path instanceDir, ProcessState state) throws IOException {
if (manifest.files() != null) {
filesLoop: for (ModrinthModpackManifest.File file : manifest.files()) {
Path path = instanceDir.getParent().resolve(file.path()).toAbsolutePath().normalize();
if (!path.startsWith(instanceDir)) throw new IOException("Pack attempted to write file outside instance. This is unsupported!");
Path path = instanceDir.resolve(file.path()).toAbsolutePath().normalize();
if (!path.startsWith(instanceDir)) throw new IOException("Pack attempted to write file outside instance which is dangerous and thus unsupported: " + path);
String sha1 = file.hashes().sha1();
IOException failedDownload = new IOException("Could not download file");
for (String url : file.downloads()) {

View File

@ -105,7 +105,7 @@ public record Instance(String id, Path path, InstanceMeta meta, ModsDirScanner m
public static void setSetupLock(Path instanceDir, boolean state) throws IOException {
if (Files.exists(instanceDir.resolve(SETUP_LOCK_NAME))) {
if (!state) Files.delete(instanceDir.resolve(SETUP_LOCK_NAME));
if (!state) Files.deleteIfExists(instanceDir.resolve(SETUP_LOCK_NAME));
} else {
if (state) Files.createDirectories(instanceDir.resolve(SETUP_LOCK_NAME));
}
@ -116,7 +116,7 @@ public record Instance(String id, Path path, InstanceMeta meta, ModsDirScanner m
try {
if (ProcessUtils.isProcessAlive(Files.readString(path.resolve(LOCK_NAME))))
return true;
Files.delete(path.resolve(LOCK_NAME));
Files.deleteIfExists(path.resolve(LOCK_NAME));
} catch (IOException e) {
Utils.LOGGER.error("Could not read running lock of " + getName(), e);
}