fix: defensively use deleteIfExists to prevent races in Instance
This commit is contained in:
parent
7a7d009e29
commit
bcd4e34f7a
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue