You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2022/06/06 11:40:04 UTC
[tomcat] branch 10.0.x updated: Don't try and clean directory that doesn't exists + refactoring
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 10.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.0.x by this push:
new 58eb860703 Don't try and clean directory that doesn't exists + refactoring
58eb860703 is described below
commit 58eb860703066051e91f691da33cb993a6fe198a
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 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 225d534f14..732f148b39 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.0.23 (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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org