This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new 44044106be Don't try and clean directory that doesn't exists + refactoring 44044106be is described below commit 44044106be18101d3c5e9a824681db847f66839b Author: Mark Thomas <ma...@apache.org> AuthorDate: Mon Jun 6 12:37:48 2022 +0100 Don't try and clean directory that doesn't exists + refactoring Avoid error message by not trying to clean up old files from the logging directory before the directory has been created. Based on #521 by HanLi. Refactor obtaining Path for a given directory --- java/org/apache/juli/FileHandler.java | 9 +++++++-- webapps/docs/changelog.xml | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/java/org/apache/juli/FileHandler.java b/java/org/apache/juli/FileHandler.java index 38e50c111e..7e3cfc8ddc 100644 --- a/java/org/apache/juli/FileHandler.java +++ b/java/org/apache/juli/FileHandler.java @@ -25,6 +25,7 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.nio.file.DirectoryStream; +import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.security.AccessController; @@ -527,7 +528,7 @@ public class FileHandler extends Handler { } private void clean() { - if (maxDays <= 0) { + if (maxDays <= 0 || Files.notExists(getDirectoryAsPath())) { return; } DELETE_FILES_SERVICE.submit(new Runnable() { @@ -549,7 +550,7 @@ public class FileHandler extends Handler { private DirectoryStream<Path> streamFilesForDelete() throws IOException { final Date maxDaysOffset = getMaxDaysOffset(); final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); - return Files.newDirectoryStream(new File(directory).toPath(), + return Files.newDirectoryStream(getDirectoryAsPath(), new DirectoryStream.Filter<Path>() { @Override @@ -569,6 +570,10 @@ public class FileHandler extends Handler { }); } + private Path getDirectoryAsPath() { + return FileSystems.getDefault().getPath(directory); + } + private String obtainDateFromPath(Path path) { Path fileName = path.getFileName(); if (fileName == null) { diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index c7b1dd71fd..17d1d88eb0 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -129,6 +129,11 @@ Include the major version in the recommended version used for Tomcat Native with the <code>AprLifecycleListener</code>. (markt) </add> + <fix> + <bug>66104</bug>: Avoid error message by not trying to clean up old + files from the logging directory before the directory has been created. + Based on <pr>521</pr> by HanLi. (markt) + </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