Skip to content

Commit

Permalink
Use atomic moves if available
Browse files Browse the repository at this point in the history
  • Loading branch information
FiniteReality committed May 25, 2024
1 parent b16034d commit 84e9b17
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions patches/net/minecraft/nbt/NbtIo.java.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- a/net/minecraft/nbt/NbtIo.java
+++ b/net/minecraft/nbt/NbtIo.java
@@ -72,12 +_,15 @@
@@ -72,12 +_,19 @@
}

public static void writeCompressed(CompoundTag p_128945_, Path p_309705_) throws IOException {
Expand All @@ -13,11 +13,15 @@
) {
writeCompressed(p_128945_, outputstream1);
}
+ Files.move(tempFile, p_309705_, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
+ try {
+ Files.move(tempFile, p_309705_, java.nio.file.StandardCopyOption.ATOMIC_MOVE);
+ } catch(java.nio.file.AtomicMoveNotSupportedException e) {
+ Files.move(tempFile, p_309705_, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
+ }
}

public static void writeCompressed(CompoundTag p_128948_, OutputStream p_128949_) throws IOException {
@@ -87,13 +_,16 @@
@@ -87,13 +_,20 @@
}

public static void write(CompoundTag p_128956_, Path p_309549_) throws IOException {
Expand All @@ -31,7 +35,11 @@
) {
write(p_128956_, dataoutputstream);
}
+ Files.move(tempFile, p_309549_, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
+ try {
+ Files.move(tempFile, p_309549_, java.nio.file.StandardCopyOption.ATOMIC_MOVE);
+ } catch(java.nio.file.AtomicMoveNotSupportedException e) {
+ Files.move(tempFile, p_309549_, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
+ }
}

@Nullable
Expand Down

0 comments on commit 84e9b17

Please sign in to comment.