From 8ec1d3d2795454688e893fb043a75ecdd2153fca Mon Sep 17 00:00:00 2001
From: Robert Scott <code@humanleg.org.uk>
Date: Sun, 7 Jan 2018 22:38:13 +0000
Subject: [PATCH v1 3/4] PluginHandler.installDownloadedPlugins: check
 downloaded plugin is valid *before* we delete any existing one

the previous behaviour could turn out to be extremely annoying
---
 src/org/openstreetmap/josm/plugins/PluginHandler.java | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/org/openstreetmap/josm/plugins/PluginHandler.java b/src/org/openstreetmap/josm/plugins/PluginHandler.java
index c36a3a664..09c900140 100644
--- a/src/org/openstreetmap/josm/plugins/PluginHandler.java
+++ b/src/org/openstreetmap/josm/plugins/PluginHandler.java
@@ -1255,13 +1255,6 @@ public final class PluginHandler {
             final String filePath = updatedPlugin.getPath();
             File plugin = new File(filePath.substring(0, filePath.length() - 4));
             String pluginName = updatedPlugin.getName().substring(0, updatedPlugin.getName().length() - 8);
-            if (plugin.exists() && !plugin.delete() && dowarn) {
-                Logging.warn(tr("Failed to delete outdated plugin ''{0}''.", plugin.toString()));
-                Logging.warn(tr("Failed to install already downloaded plugin ''{0}''. " +
-                        "Skipping installation. JOSM is still going to load the old plugin version.",
-                        pluginName));
-                continue;
-            }
             try {
                 // Check the plugin is a valid and accessible JAR file before installing it (fix #7754)
                 new JarFile(updatedPlugin).close();
@@ -1272,6 +1265,13 @@ public final class PluginHandler {
                 }
                 continue;
             }
+            if (plugin.exists() && !plugin.delete() && dowarn) {
+                Logging.warn(tr("Failed to delete outdated plugin ''{0}''.", plugin.toString()));
+                Logging.warn(tr("Failed to install already downloaded plugin ''{0}''. " +
+                        "Skipping installation. JOSM is still going to load the old plugin version.",
+                        pluginName));
+                continue;
+            }
             // Install plugin
             if (!updatedPlugin.renameTo(plugin) && dowarn) {
                 Logging.warn(tr("Failed to install plugin ''{0}'' from temporary download file ''{1}''. Renaming failed.",
-- 
2.11.0

