Better to fail updating the version number than crashing.

If we update the number, we have to also use the "empty file" trick
to remove the old file, which will crash ProtocolLib on the first 
reload. It takes a second reload for it to function at all.

It's much better to take the hit on the version number, and avoid 
this issue altogether. The update method simply wasn't designed for 
plugins with version numbers in their file name.
This commit is contained in:
Kristian S. Stangeland 2014-04-18 00:27:25 +02:00
parent 19ea5dfc33
commit 17dda7f032

View File

@ -599,18 +599,14 @@ public class Updater {
private void performUpdate() { private void performUpdate() {
if ((Updater.this.versionLink != null) && (Updater.this.type != UpdateType.NO_DOWNLOAD)) { if ((Updater.this.versionLink != null) && (Updater.this.type != UpdateType.NO_DOWNLOAD)) {
final String oldFileName = Updater.this.file.getName();
final File pluginFolder = plugin.getDataFolder().getParentFile(); final File pluginFolder = plugin.getDataFolder().getParentFile();
File destinationFolder = new File(pluginFolder, updateFolder); File destinationFolder = new File(pluginFolder, updateFolder);
String name = versionFileName; String name = Updater.this.file.getName();
// Oh - this is a problem - we'll have to create an empty plugin to remove the old version (after two reloads) // If it's a zip file, it shouldn't be downloaded as the plugin's name
if (!versionFileName.equals(oldFileName)) { if (Updater.this.versionLink.endsWith(".zip")) {
createEmptyFile(new File(destinationFolder, oldFileName)); name = versionFileName;
destinationFolder = pluginFolder;
plugin.getLogger().info("Creating empty plugin file. Note that the server may need to be reloaded twice.");
} }
Updater.this.saveFile( Updater.this.saveFile(
destinationFolder, destinationFolder,
name, name,
@ -620,14 +616,5 @@ public class Updater {
Updater.this.result = UpdateResult.UPDATE_AVAILABLE; Updater.this.result = UpdateResult.UPDATE_AVAILABLE;
} }
} }
private void createEmptyFile(File emptyFile) {
try {
emptyFile.delete();
Files.touch(emptyFile);
} catch (IOException e) {
throw new RuntimeException("Cannot create empty JAR-file.", e);
}
}
} }
} }