From 234dff888d8c8747aa86a75cfea8e00d294399c3 Mon Sep 17 00:00:00 2001 From: zzz Date: Thu, 13 May 2010 17:04:16 +0000 Subject: [PATCH] Try to prevent ZipErrors after plugin update --- .../src/net/i2p/router/web/WebAppStarter.java | 27 +++++++++++++++++++ history.txt | 4 +++ .../src/net/i2p/router/RouterVersion.java | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/apps/routerconsole/java/src/net/i2p/router/web/WebAppStarter.java b/apps/routerconsole/java/src/net/i2p/router/web/WebAppStarter.java index 6bd9b0e1f7..0264d6307a 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/WebAppStarter.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/WebAppStarter.java @@ -3,10 +3,13 @@ package net.i2p.router.web; import java.io.File; import java.io.IOException; import java.util.Collection; +import java.util.Map; import java.util.Properties; import java.util.StringTokenizer; +import java.util.concurrent.ConcurrentHashMap; import net.i2p.I2PAppContext; +import net.i2p.util.FileUtil; import org.mortbay.http.HttpContext; import org.mortbay.http.HttpListener; @@ -31,6 +34,8 @@ import org.mortbay.jetty.servlet.WebApplicationContext; */ public class WebAppStarter { + static final Map warModTimes = new ConcurrentHashMap(); + /** * adds and starts * @throws just about anything, caller would be wise to catch Throwable @@ -54,6 +59,28 @@ public class WebAppStarter { stopWebApp(server, appName); } catch (Throwable t) {} + // To avoid ZipErrors from JarURLConnetion caching, + // (used by Jetty JarResource and JarFileResource) + // copy the war to a new directory if it is newer than the one we loaded originally. + // Yes, URLConnection has a setDefaultUseCaches() method, but it's hard to get to + // because it's non-static and the class is abstract, and we don't really want to + // set the default to false for everything. + long newmod = (new File(warPath)).lastModified(); + if (newmod <= 0) + throw new IOException("Web app " + warPath + " does not exist"); + Long oldmod = warModTimes.get(warPath); + if (oldmod == null) { + warModTimes.put(warPath, new Long(newmod)); + } else if (oldmod.longValue() < newmod) { + // copy war to temporary directory + File warTmpDir = new File(ctx.getTempDir(), "war-copy-" + appName + ctx.random().nextInt()); + warTmpDir.mkdir(); + String tmpPath = (new File(warTmpDir, appName + ".war")).getAbsolutePath(); + if (!FileUtil.copy(warPath, tmpPath, true)) + throw new IOException("Web app failed copy from " + warPath + " to " + tmpPath); + warPath = tmpPath; + } + WebApplicationContext wac = server.addWebApplication("/"+ appName, warPath); tmpdir.mkdir(); wac.setTempDirectory(tmpdir); diff --git a/history.txt b/history.txt index 0d212c15fd..b728a9f3a7 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,7 @@ +2010-05-13 zzz + * netdb.jsp debug tweaks + * Plugins: Try to prevent ZipErrors after upgrade + 2010-05-10 zzz * Console: - Summary bar tweaks diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 4e28a2c8d2..c10128fe62 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 5; + public final static long BUILD = 6; /** for example "-test" */ public final static String EXTRA = "";