Author: markt Date: Wed Mar 30 17:39:54 2011 New Revision: 1087026 URL: http://svn.apache.org/viewvc?rev=1087026&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50984 When using the Manager application ensure that undeployment is reported as failed if a file cannot be deleted.
Modified: tomcat/trunk/java/org/apache/catalina/manager/LocalStrings.properties tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/catalina/manager/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/manager/LocalStrings.properties?rev=1087026&r1=1087025&r2=1087026&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/manager/LocalStrings.properties (original) +++ tomcat/trunk/java/org/apache/catalina/manager/LocalStrings.properties Wed Mar 30 17:39:54 2011 @@ -69,6 +69,7 @@ htmlManagerServlet.title=Tomcat Web Appl managerServlet.alreadyContext=FAIL - Application already exists at path {0} managerServlet.alreadyDocBase=FAIL - Directory {0} is already in use managerServlet.configured=OK - Deployed application from context file {0} +managerServlet.deleteFail=FAIL - Unable to delete [{0}]. The continued presence of this file may cause problems. managerServlet.deployed=OK - Deployed application at context path {0} managerServlet.deployFailed=FAIL - Failed to deploy application at context path {0} managerServlet.deployedButNotStarted=FAIL - Deployed application at context path {0} but context failed to start @@ -78,6 +79,7 @@ managerServlet.invalidPath=FAIL - Invali managerServlet.invalidWar=FAIL - Invalid application URL {0} was specified managerServlet.listed=OK - Listed applications for virtual host {0} managerServlet.listitem={0}:{1}:{2}:{3} +managerServlet.mkdirFail=FAIL - Unable to create directory [{0}] managerServlet.noAppBase=FAIL - Cannot identify application base for context path {0} managerServlet.noCommand=FAIL - No command was specified managerServlet.noContext=FAIL - No context exists for path {0} Modified: tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java?rev=1087026&r1=1087025&r2=1087026&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java (original) +++ tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java Wed Mar 30 17:39:54 2011 @@ -627,7 +627,11 @@ public class ManagerServlet extends Http File deployedPath = deployed; if (tag != null) { deployedPath = new File(versioned, tag); - deployedPath.mkdirs(); + if (!deployedPath.isDirectory() && !deployedPath.mkdirs()) { + writer.println(smClient.getString("managerServlet.mkdirFail", + deployedPath)); + return; + } } // Upload the web application archive to a local WAR file @@ -642,7 +646,7 @@ public class ManagerServlet extends Http addServiced(name); try { // Upload WAR - uploadWar(request, localWar); + uploadWar(writer, request, localWar, smClient); // Copy WAR and XML to the host app base if needed if (tag != null) { deployedPath = deployed; @@ -817,7 +821,11 @@ public class ManagerServlet extends Http addServiced(name); try { if (config != null) { - configBase.mkdirs(); + if (!configBase.isDirectory() && !configBase.mkdirs()) { + writer.println(smClient.getString( + "managerServlet.mkdirFail",configBase)); + return; + } copy(new File(config), new File(configBase, baseName + ".xml")); } @@ -1333,12 +1341,18 @@ public class ManagerServlet extends Http File war = new File(getAppBase(), baseName + ".war"); File dir = new File(getAppBase(), baseName); File xml = new File(configBase, baseName + ".xml"); - if (war.exists()) { - war.delete(); - } else if (dir.exists()) { - undeployDir(dir); - } else { - xml.delete(); + if (war.exists() && !war.delete()) { + writer.println(smClient.getString( + "managerServlet.deleteFail", war)); + return; + } else if (dir.exists() && !undeployDir(dir)) { + writer.println(smClient.getString( + "managerServlet.deleteFail", dir)); + return; + } else if (xml.exists() && !xml.delete()) { + writer.println(smClient.getString( + "managerServlet.deleteFail", xml)); + return; } // Perform new deployment check(name); @@ -1446,11 +1460,11 @@ public class ManagerServlet extends Http /** * Delete the specified directory, including all of its contents and - * subdirectories recursively. + * subdirectories recursively. The code assumes that the directory exists. * - * @param dir File object representing the directory to be deleted + * @param dir File object representing the directory to be deleted. */ - protected void undeployDir(File dir) { + protected boolean undeployDir(File dir) { String files[] = dir.list(); if (files == null) { @@ -1459,13 +1473,16 @@ public class ManagerServlet extends Http for (int i = 0; i < files.length; i++) { File file = new File(dir, files[i]); if (file.isDirectory()) { - undeployDir(file); + if (!undeployDir(file)) { + return false; + } } else { - file.delete(); + if (!file.delete()) { + return false; + } } } - dir.delete(); - + return dir.delete(); } @@ -1473,15 +1490,21 @@ public class ManagerServlet extends Http * Upload the WAR file included in this request, and store it at the * specified file location. * - * @param request The servlet request we are processing - * @param war The file into which we should store the uploaded WAR + * @param writer Writer to render to + * @param request The servlet request we are processing + * @param war The file into which we should store the uploaded WAR + * @param smClient The StringManager used to construct i18n messages based + * on the Locale of the client * * @exception IOException if an I/O error occurs during processing */ - protected void uploadWar(HttpServletRequest request, File war) - throws IOException { + protected void uploadWar(PrintWriter writer, HttpServletRequest request, + File war, StringManager smClient) throws IOException { - war.delete(); + if (war.exists() && !war.delete()) { + String msg = smClient.getString("managerServlet.deleteFail", war); + throw new IOException(msg); + } ServletInputStream istream = null; BufferedOutputStream ostream = null; try { @@ -1502,7 +1525,10 @@ public class ManagerServlet extends Http istream.close(); istream = null; } catch (IOException e) { - war.delete(); + if (war.exists() && !war.delete()) { + writer.println( + smClient.getString("managerServlet.deleteFail", war)); + } throw e; } finally { if (ostream != null) { Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1087026&r1=1087025&r2=1087026&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Wed Mar 30 17:39:54 2011 @@ -181,6 +181,10 @@ Prevent the custom error pages for the Manager and Host Manager applications from being accessed directly. (markt) </fix> + <fix> + <bug>50984</bug>: When using the Manager application ensure that + undeployment fails if a file cannot be deleted. (markt) + </fix> </changelog> </subsection> <subsection name="Other"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org