aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorWarrior <[email protected]>2024-12-23 16:29:28 +0100
committerGitHub <[email protected]>2024-12-23 16:29:28 +0100
commitbd4c235c2f2f2f64a50aabceab810db7d8763793 (patch)
tree4282ca50192cce96ddf3e211b5fcf05156702e07
parent62d4130bbaeb6e6bcd41e72f9a512ab90d0486b3 (diff)
downloadPaper-bd4c235c2f2f2f64a50aabceab810db7d8763793.tar.gz
Paper-bd4c235c2f2f2f64a50aabceab810db7d8763793.zip
Throw during plugin update folder process on failed rename/delete (#11784)
-rw-r--r--paper-server/src/main/java/io/papermc/paper/plugin/provider/source/FileProviderSource.java24
1 files changed, 17 insertions, 7 deletions
diff --git a/paper-server/src/main/java/io/papermc/paper/plugin/provider/source/FileProviderSource.java b/paper-server/src/main/java/io/papermc/paper/plugin/provider/source/FileProviderSource.java
index 48604e7f96..a0b84535a9 100644
--- a/paper-server/src/main/java/io/papermc/paper/plugin/provider/source/FileProviderSource.java
+++ b/paper-server/src/main/java/io/papermc/paper/plugin/provider/source/FileProviderSource.java
@@ -9,7 +9,6 @@ import io.papermc.paper.plugin.provider.type.PluginFileType;
import org.bukkit.plugin.InvalidPluginException;
import org.jetbrains.annotations.Nullable;
-import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
@@ -99,7 +98,7 @@ public class FileProviderSource implements ProviderSource<Path, Path> {
/**
* Replaces a plugin with a plugin of the same plugin name in the update folder.
*
- * @param file
+ * @param file The plugin jar file to look for updates for.
*/
private Path checkUpdate(Path file) throws InvalidPluginException {
PluginInitializerManager pluginSystem = PluginInitializerManager.instance();
@@ -121,11 +120,22 @@ public class FileProviderSource implements ProviderSource<Path, Path> {
throw new RuntimeException("Could not copy '" + updateLocation + "' to '" + file + "' in update plugin process", exception);
}
- // Idk what this is about, TODO
- File newName = new File(file.toFile().getParentFile(), updateLocation.toFile().getName());
- file.toFile().renameTo(newName);
- updateLocation.toFile().delete();
- return newName.toPath();
+ // Rename the plugin file to the update file's name.
+ final Path renamedFile = file.resolveSibling(updateLocation.getFileName());
+ try {
+ Files.move(file, renamedFile, StandardCopyOption.REPLACE_EXISTING);
+ } catch (IOException exception) {
+ throw new RuntimeException("Could not rename '" + file + "' to '" + renamedFile + "' in update plugin process", exception);
+ }
+
+ // Delete the file from the update folder now that it's copied over successfully
+ try {
+ Files.delete(updateLocation);
+ } catch (IOException exception) {
+ throw new RuntimeException("Could not delete '" + updateLocation + "' from update folder in update plugin process", exception);
+ }
+
+ return renamedFile;
}
} catch (Exception e) {
throw new InvalidPluginException(e);