From bcd4e34f7a64ea22e658eee029dc5c8d6427b7d8 Mon Sep 17 00:00:00 2001 From: JFronny Date: Tue, 3 Oct 2023 20:15:11 +0200 Subject: [PATCH] fix: defensively use deleteIfExists to prevent races in Instance --- .../jfronny/inceptum/launcher/system/instance/Instance.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/Instance.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/Instance.java index 9c138c0..38340d1 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/Instance.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/instance/Instance.java @@ -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); }