From 698b3152cf2b7b507c25009f3f35a3e0852660a5 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Fri, 10 Jun 2022 10:01:09 -0700 Subject: [PATCH] Improve migration file errors (#7929) --- patches/server/0004-Paper-config-files.patch | 28 +++++++++++++------ patches/server/0352-Anti-Xray.patch | 4 +-- ...4-Bukkit-world-container-is-not-used.patch | 4 +-- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/patches/server/0004-Paper-config-files.patch b/patches/server/0004-Paper-config-files.patch index 0c29d36a03..2e8cc4cd31 100644 --- a/patches/server/0004-Paper-config-files.patch +++ b/patches/server/0004-Paper-config-files.patch @@ -847,10 +847,10 @@ index 0000000000000000000000000000000000000000..69add4a7f1147015806bc9b63a8340d1 +} diff --git a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java new file mode 100644 -index 0000000000000000000000000000000000000000..be64437ba7630fe069aaea502932b514c85162f8 +index 0000000000000000000000000000000000000000..bc46e342b398dc56c976702d98ff3646995eb41e --- /dev/null +++ b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java -@@ -0,0 +1,384 @@ +@@ -0,0 +1,396 @@ +package io.papermc.paper.configuration; + +import com.google.common.base.Suppliers; @@ -926,7 +926,8 @@ index 0000000000000000000000000000000000000000..be64437ba7630fe069aaea502932b514 + static final String GLOBAL_CONFIG_FILE_NAME = "paper-global.yml"; + static final String WORLD_DEFAULTS_CONFIG_FILE_NAME = "paper-world-defaults.yml"; + static final String WORLD_CONFIG_FILE_NAME = "paper-world.yml"; -+ private static final Path BACKUP_DIR = Path.of("legacy-backup"); ++ public static final String CONFIG_DIR = "config"; ++ private static final String BACKUP_DIR ="legacy-backup"; + + private static final String GLOBAL_HEADER = """ + This is the global configuration file for Paper. @@ -1139,12 +1140,23 @@ index 0000000000000000000000000000000000000000..be64437ba7630fe069aaea502932b514 + public static PaperConfigurations setup(final Path legacyConfig, final Path configDir, final Path worldFolder, final File spigotConfig) throws Exception { + if (needsConverting(legacyConfig)) { + try { -+ Files.createDirectories(configDir.resolve(BACKUP_DIR)); -+ final Path legacyConfigBackup = configDir.resolve(BACKUP_DIR).resolve(legacyConfig.getFileName().toString() + ".old"); ++ if (Files.exists(configDir) && !Files.isDirectory(configDir)) { ++ throw new RuntimeException("Paper needs to create a '" + CONFIG_DIR + "' folder in the root of your server. You already have a non-directory named '" + CONFIG_DIR + "'. Please remove it and restart the server."); ++ } ++ final Path backupDir = configDir.resolve(BACKUP_DIR); ++ if (Files.exists(backupDir) && !Files.isDirectory(backupDir)) { ++ throw new RuntimeException("Paper needs to create a '" + BACKUP_DIR + "' directory in the '" + CONFIG_DIR + "' folder. You already have a non-directory named '" + BACKUP_DIR + "'. Please remove it and restart the server."); ++ } ++ Files.createDirectories(backupDir); ++ final String backupFileName = legacyConfig.getFileName().toString() + ".old"; ++ final Path legacyConfigBackup = backupDir.resolve(backupFileName); ++ if (Files.exists(legacyConfigBackup) && !Files.isRegularFile(legacyConfigBackup)) { ++ throw new RuntimeException("Paper needs to create a '" + backupFileName + "' file in the '" + BACKUP_DIR + "' folder. You already have a non-file named '" + backupFileName + "'. Please remove it and restart the server."); ++ } + Files.move(legacyConfig, legacyConfigBackup, StandardCopyOption.REPLACE_EXISTING); // make backup + convert(legacyConfigBackup, configDir, worldFolder, spigotConfig); + } catch (final IOException ex) { -+ throw new RuntimeException("Could not convert paper.yml to the new configuration format", ex); ++ throw new RuntimeException("Could not convert '" + legacyConfig.getFileName().toString() + "' to the new configuration format", ex); + } + } + try { @@ -4020,7 +4032,7 @@ index 6cc81495d8d09ff1fbb09f2e63a16ec4fa6138ec..73662a463fc9d38b39c4c779fcfaa09a // CraftBukkit end diff --git a/src/main/java/net/minecraft/server/Services.java b/src/main/java/net/minecraft/server/Services.java -index 697ca7457115423a8c4d8a7d1f7a353237b56509..86c218e41fbe2a55b1319b37d26fd5da4f0b3da6 100644 +index 697ca7457115423a8c4d8a7d1f7a353237b56509..3997024eca83af2d82132de3bb5770e155659797 100644 --- a/src/main/java/net/minecraft/server/Services.java +++ b/src/main/java/net/minecraft/server/Services.java @@ -7,14 +7,28 @@ import java.io.File; @@ -4050,7 +4062,7 @@ index 697ca7457115423a8c4d8a7d1f7a353237b56509..86c218e41fbe2a55b1319b37d26fd5da SignatureValidator signatureValidator = SignatureValidator.from(authenticationService.getServicesKey()); - return new Services(minecraftSessionService, signatureValidator, gameProfileRepository, gameProfileCache); + // Paper start -+ io.papermc.paper.configuration.PaperConfigurations paperConfigurations = io.papermc.paper.configuration.PaperConfigurations.setup(((File) optionSet.valueOf("paper-settings")).toPath(), java.nio.file.Path.of("config"), rootDirectory.toPath(), (File) optionSet.valueOf("spigot-settings")); ++ io.papermc.paper.configuration.PaperConfigurations paperConfigurations = io.papermc.paper.configuration.PaperConfigurations.setup(((File) optionSet.valueOf("paper-settings")).toPath(), java.nio.file.Path.of(io.papermc.paper.configuration.PaperConfigurations.CONFIG_DIR), rootDirectory.toPath(), (File) optionSet.valueOf("spigot-settings")); + return new Services(minecraftSessionService, signatureValidator, gameProfileRepository, gameProfileCache, paperConfigurations); + // Paper end } diff --git a/patches/server/0352-Anti-Xray.patch b/patches/server/0352-Anti-Xray.patch index 9c4b098db8..3a55255cdc 100644 --- a/patches/server/0352-Anti-Xray.patch +++ b/patches/server/0352-Anti-Xray.patch @@ -1017,7 +1017,7 @@ index 0000000000000000000000000000000000000000..80a2dfb266ae1221680a7b24fee2f7e2 + } +} diff --git a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java -index be64437ba7630fe069aaea502932b514c85162f8..922ce2f0f4fa10c585939d6682b1a0a8612de0ea 100644 +index bc46e342b398dc56c976702d98ff3646995eb41e..39522b2150106082754150ca77cb04e80ae35fac 100644 --- a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java +++ b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java @@ -1,5 +1,6 @@ @@ -1027,7 +1027,7 @@ index be64437ba7630fe069aaea502932b514c85162f8..922ce2f0f4fa10c585939d6682b1a0a8 import com.google.common.base.Suppliers; import com.google.common.collect.Table; import com.mojang.logging.LogUtils; -@@ -191,6 +192,7 @@ public class PaperConfigurations extends Configurations