This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push: new 9520015c12 Don't try and clean directory that doesn't exists + refactoring 9520015c12 is described below commit 9520015c12d518d97ac83e27e8f9c77316ac5c81 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 | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/java/org/apache/juli/FileHandler.java b/java/org/apache/juli/FileHandler.java index 0634a29fd5..974756aba1 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; @@ -537,7 +538,7 @@ public class FileHandler extends Handler { } private void clean() { - if (maxDays.intValue() <= 0) { + if (maxDays.intValue() <= 0 || Files.notExists(getDirectoryAsPath())) { return; } DELETE_FILES_SERVICE.submit(() -> { @@ -554,7 +555,7 @@ public class FileHandler extends Handler { private DirectoryStream<Path> streamFilesForDelete() throws IOException { LocalDate maxDaysOffset = LocalDate.now().minus(maxDays.intValue(), ChronoUnit.DAYS); - return Files.newDirectoryStream(new File(directory).toPath(), path -> { + return Files.newDirectoryStream(getDirectoryAsPath(), path -> { boolean result = false; String date = obtainDateFromPath(path); if (date != null) { @@ -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 132af3f39b..deed19fd17 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -105,6 +105,15 @@ issues do not "pop up" wrt. others). --> <section name="Tomcat 9.0.65 (remm)" rtext="in development"> + <subsection name="Catalina"> + <changelog> + <fix> + 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="Jasper"> <changelog> <add> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org