From 33b1972657447be9545577a8271a8973927857ce Mon Sep 17 00:00:00 2001 From: dek Date: Tue, 1 Dec 2026 18:14:42 -0300 Subject: [PATCH] Write config temp files next to the target so the move stays atomic --- .../meteorclient/systems/System.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/systems/System.java b/src/main/java/meteordevelopment/meteorclient/systems/System.java index 695196d17aa..2a4b0c122fd 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/System.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/System.java @@ -49,15 +49,17 @@ public void save(File folder) { CompoundTag tag = toTag(); if (tag == null) return; + if (folder != null) file = new File(folder, file.getName()); + Path tempFile = null; try { - tempFile = Files.createTempFile(MeteorClient.MOD_ID, file.getName()); - NbtIo.write(tag, tempFile); - - if (folder != null) file = new File(folder, file.getName()); - Files.createDirectories(file.toPath().getParent()); + // The temp file has to live next to the target, otherwise the move crosses a filesystem + // boundary and falls back to a copy that replaces the old file in place + tempFile = Files.createTempFile(file.toPath().getParent(), file.getName(), ".tmp"); + NbtIo.write(tag, tempFile); + try { Files.move(tempFile, file.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE); } catch (AtomicMoveNotSupportedException _) {