2018-09-01 06:56:57 +08:00
|
|
|
From e232364bbe6742e92b63345842d63483cdcfe77f Mon Sep 17 00:00:00 2001
|
2018-08-11 12:55:42 +08:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Sat, 11 Aug 2018 00:49:20 -0400
|
|
|
|
Subject: [PATCH] Detect and repair corrupt Region Files
|
|
|
|
|
|
|
|
If the file has partial data written but not the full 8192 bytes,
|
|
|
|
then the server will be unable to load that region file...
|
|
|
|
|
|
|
|
I don't know why mojang only checks for 4096, when anything less than 8192 is a crash.
|
|
|
|
|
|
|
|
But to be safe, it will attempt to back up the file.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/RegionFile.java b/src/main/java/net/minecraft/server/RegionFile.java
|
2018-09-01 06:56:57 +08:00
|
|
|
index 5d2853b9ce..c35974aa7c 100644
|
2018-08-11 12:55:42 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/RegionFile.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/RegionFile.java
|
2018-09-01 06:56:57 +08:00
|
|
|
@@ -40,7 +40,20 @@ public class RegionFile {
|
2018-08-11 12:55:42 +08:00
|
|
|
}
|
|
|
|
|
2018-09-01 06:56:57 +08:00
|
|
|
this.c = new RandomAccessFile(file1, "rw");
|
2018-08-11 12:55:42 +08:00
|
|
|
- if (this.c.length() < 4096L) {
|
|
|
|
+ // Paper start - detect and fix incomplete headers
|
|
|
|
+ long length = this.c.length();
|
|
|
|
+ if (length < 8192 && length > 0) {
|
2018-09-01 06:56:57 +08:00
|
|
|
+ File corrupt = new File(file1.getParentFile(), file1.getName() + ".bak");
|
2018-08-11 12:55:42 +08:00
|
|
|
+ org.apache.logging.log4j.Logger logger = org.apache.logging.log4j.LogManager.getLogger();
|
2018-09-01 06:56:57 +08:00
|
|
|
+ logger.error("Region file " + file1 + " was incomplete. Backing up to " + corrupt + " and repairing");
|
2018-08-11 12:55:42 +08:00
|
|
|
+ try {
|
2018-09-01 06:56:57 +08:00
|
|
|
+ java.nio.file.Files.copy(file1.toPath(), corrupt.toPath());
|
2018-08-11 12:55:42 +08:00
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ logger.error("Error backing up corrupt file", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (length < 8192L) {
|
|
|
|
+ // Paper end
|
2018-09-01 06:56:57 +08:00
|
|
|
this.c.write(a);
|
|
|
|
this.c.write(a);
|
2018-08-11 12:55:42 +08:00
|
|
|
this.g += 8192;
|
|
|
|
--
|
|
|
|
2.18.0
|
|
|
|
|