aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0830-Only-write-chunk-data-to-disk-if-it-serializes-witho.patch
blob: f6365f90b4d884909f07c23e8ca378c3b4cfe4af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Sun, 19 Dec 2021 09:13:41 -0800
Subject: [PATCH] Only write chunk data to disk if it serializes without
 throwing

This ensures at least a valid version of the chunk exists
on disk, even if outdated

diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
index 2dde10324e515bd58fc6ba7e93156ae783492cc2..c7216cf3317cbd49b032c44feb370c50928dd21e 100644
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
@@ -298,10 +298,11 @@ public class RegionFileStorage implements AutoCloseable {
                 NbtIo.write(nbt, (DataOutput) dataoutputstream);
                 regionfile.setStatus(pos.x, pos.z, ChunkSerializer.getStatus(nbt)); // Paper - cache status on disk
                 regionfile.setOversized(pos.x, pos.z, false); // Paper - We don't do this anymore, mojang stores differently, but clear old meta flag if it exists to get rid of our own meta file once last oversized is gone
+                dataoutputstream.close(); // Paper - only write if successful
             } catch (Throwable throwable) {
                 if (dataoutputstream != null) {
                     try {
-                        dataoutputstream.close();
+                        //dataoutputstream.close(); // Paper - don't write garbage data to disk if writing serialization fails
                     } catch (Throwable throwable1) {
                         throwable.addSuppressed(throwable1);
                     }
@@ -309,10 +310,7 @@ public class RegionFileStorage implements AutoCloseable {
 
                 throw throwable;
             }
-
-            if (dataoutputstream != null) {
-                dataoutputstream.close();
-            }
+            // Paper - move into try block to only write if successfully serialized
         }
 
             // Paper start