This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 8ffc799b2d533437f3d2e7731b010ebad5e14206 Author: Mark Thomas <[email protected]> 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 189529750a..92118f75c0 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; @@ -538,7 +539,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(() -> { @@ -555,7 +556,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) { @@ -570,6 +571,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 9ad990a912..4a88e9974a 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 10.1.0-M16 (markt)" 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: [email protected] For additional commands, e-mail: [email protected]
