This is an automated email from the ASF dual-hosted git repository.

remm 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 2c8b2e2010 Optimize directory listing
2c8b2e2010 is described below

commit 2c8b2e2010ff71a1b02729650f9ce165fabc67ee
Author: remm <r...@apache.org>
AuthorDate: Fri Apr 4 10:45:11 2025 +0200

    Optimize directory listing
    
    69643: Optimize directory listing for large amount of files.
    Patch submitted by  Loic de l'Eprevier.
---
 java/org/apache/catalina/webresources/DirResourceSet.java | 5 ++++-
 webapps/docs/changelog.xml                                | 4 ++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/catalina/webresources/DirResourceSet.java 
b/java/org/apache/catalina/webresources/DirResourceSet.java
index 6259b81f7e..4e7e6ad47e 100644
--- a/java/org/apache/catalina/webresources/DirResourceSet.java
+++ b/java/org/apache/catalina/webresources/DirResourceSet.java
@@ -173,6 +173,7 @@ public class DirResourceSet extends AbstractFileResourceSet 
implements WebResour
             if (f != null) {
                 File[] list = f.listFiles();
                 if (list != null) {
+                    String fCanPath = null;
                     for (File entry : list) {
                         // f has already been validated so the following checks
                         // can be much simpler than those in file()
@@ -190,7 +191,9 @@ public class DirResourceSet extends AbstractFileResourceSet 
implements WebResour
                                 // that what is left does not contain a 
symlink.
                                 absPath = 
entry.getAbsolutePath().substring(f.getAbsolutePath().length());
                                 String entryCanPath = entry.getCanonicalPath();
-                                String fCanPath = f.getCanonicalPath();
+                                if (fCanPath == null) {
+                                    fCanPath = f.getCanonicalPath();
+                                }
                                 if (entryCanPath.length() >= 
fCanPath.length()) {
                                     canPath = 
entryCanPath.substring(fCanPath.length());
                                     if (absPath.equals(canPath)) {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index e687f8f86c..5328960d16 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -115,6 +115,10 @@
         Process possible path parameters rewrite production in the rewrite
         valve. (remm)
       </fix>
+      <fix>
+        <bug>69643</bug>: Optimize directory listing for large amount of files.
+        Patch submitted by  Loic de l'Eprevier. (remm)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Other">


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to