From b608d897d9c6c65d482bf58d2cb2ff6652f16ed2 Mon Sep 17 00:00:00 2001 From: markt Date: Mon, 20 Jun 2011 16:38:40 +0000 Subject: [PATCH] The fix for bug 51310 caused a regression that re-introduced bug 49957 and deleted the contents of the work directory when Tomcat was shutdown. This fix ensures that that work directory for an application is not deleted when Tomcat is shutdown. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1137693 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/catalina/startup/ContextConfig.java | 27 ++++++++++++++++++++++ webapps/docs/changelog.xml | 6 +++++ 2 files changed, 33 insertions(+) diff --git a/java/org/apache/catalina/startup/ContextConfig.java b/java/org/apache/catalina/startup/ContextConfig.java index b6d406c45..550b7714e 100644 --- a/java/org/apache/catalina/startup/ContextConfig.java +++ b/java/org/apache/catalina/startup/ContextConfig.java @@ -58,6 +58,8 @@ import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleEvent; import org.apache.catalina.LifecycleListener; import org.apache.catalina.Pipeline; +import org.apache.catalina.Server; +import org.apache.catalina.Service; import org.apache.catalina.Valve; import org.apache.catalina.Wrapper; import org.apache.catalina.core.ContainerBase; @@ -1090,6 +1092,12 @@ public class ContextConfig if (log.isDebugEnabled()) log.debug(sm.getString("contextConfig.destroy")); + // Skip clearing the work directory if Tomcat is being shutdown + Server s = getServer(); + if (s != null && !s.getState().isAvailable()) { + return; + } + // Changed to getWorkPath per Bugzilla 35819. String workDir = ((StandardContext) context).getWorkPath(); if (workDir != null) @@ -1097,6 +1105,25 @@ public class ContextConfig } + private Server getServer() { + Container c = context; + while (c != null && !(c instanceof Engine)) { + c = c.getParent(); + } + + if (c == null) { + return null; + } + + Service s = ((Engine)c).getService(); + + if (s == null) { + return null; + } + + return s.getServer(); + } + /** * Validate the usage of security role names in the web application * deployment descriptor. If any problems are found, issue warning diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 55d0eb5e7..aa7eb271b 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -72,6 +72,12 @@ Add the Tomcat extras JARs to the list of JARs to skip when scanning for TLDs and web fragments. (rjung) + + The fix for bug 51310 caused a regression that re-introduced + bug 49957 and deleted the contents of the work directory + when Tomcat was shutdown. This fix ensures that that work directory for + an application is not deleted when Tomcat is shutdown. (mark) + -- 2.11.0