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

remm pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/11.0.x by this push:
     new 958f130c52 Optimize directory listing
958f130c52 is described below

commit 958f130c52097ac984b03642c3480a2ae2e1781f
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 ae98c7ace6..7735b1f55c 100644
--- a/java/org/apache/catalina/webresources/DirResourceSet.java
+++ b/java/org/apache/catalina/webresources/DirResourceSet.java
@@ -170,6 +170,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()
@@ -187,7 +188,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 1d5f1900eb..9233dc005a 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -111,6 +111,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>
 </section>


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

Reply via email to