This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 11.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push: new be8c59972a Enhance lifecycle of temporary files used by partial PUT be8c59972a is described below commit be8c59972afbfdc25e3e8e00fe0c86aef626ca77 Author: remm <r...@apache.org> AuthorDate: Fri Jan 24 15:06:02 2025 +0100 Enhance lifecycle of temporary files used by partial PUT Delete temporary file right after finishing request processing. Simplify using createTempFile. --- java/org/apache/catalina/servlets/DefaultServlet.java | 17 +++++++---------- webapps/docs/changelog.xml | 3 +++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/java/org/apache/catalina/servlets/DefaultServlet.java b/java/org/apache/catalina/servlets/DefaultServlet.java index 3642176e01..771ba538aa 100644 --- a/java/org/apache/catalina/servlets/DefaultServlet.java +++ b/java/org/apache/catalina/servlets/DefaultServlet.java @@ -615,7 +615,7 @@ public class DefaultServlet extends HttpServlet { } InputStream resourceInputStream = null; - + File tempContentFile = null; try { // Append data specified in ranges to existing content for this // resource - create a temp. file on the local filesystem to @@ -624,8 +624,8 @@ public class DefaultServlet extends HttpServlet { if (range == IGNORE) { resourceInputStream = req.getInputStream(); } else { - File contentFile = executePartialPut(req, range, path); - resourceInputStream = new FileInputStream(contentFile); + tempContentFile = executePartialPut(req, range, path); + resourceInputStream = new FileInputStream(tempContentFile); } if (resources.write(path, resourceInputStream, true)) { @@ -649,6 +649,9 @@ public class DefaultServlet extends HttpServlet { // Ignore } } + if (tempContentFile != null) { + tempContentFile.delete(); + } } } @@ -671,13 +674,7 @@ public class DefaultServlet extends HttpServlet { // resource - create a temp. file on the local filesystem to // perform this operation File tempDir = (File) getServletContext().getAttribute(ServletContext.TEMPDIR); - // Convert all '/' characters to '.' in resourcePath - String convertedResourcePath = path.replace('/', '.'); - File contentFile = new File(tempDir, convertedResourcePath); - if (contentFile.createNewFile()) { - // Clean up contentFile when Tomcat is terminated - contentFile.deleteOnExit(); - } + File contentFile = File.createTempFile("put-part-", null, tempDir); try (RandomAccessFile randAccessContentFile = new RandomAccessFile(contentFile, "rw")) { diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 4a470c2177..feb77c567a 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -181,6 +181,9 @@ <code>IOException</code> occurs on a non-container thread during asynchronous processing. (markt) </fix> + <fix> + Enhance lifecycle of temporary files used by partial PUT. (remm) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org