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


The following commit(s) were added to refs/heads/main by this push:
     new 82367b3891 Remove the case sensitivity check
82367b3891 is described below

commit 82367b3891b9ffd501ee7046b71ee2461303562c
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Feb 20 12:49:53 2025 +0000

    Remove the case sensitivity check
    
    The performance impact is minimal and getting the check right in all
    cases is difficult due to various edge cases
---
 .../catalina/webresources/DirResourceSet.java      | 70 +++-------------------
 1 file changed, 9 insertions(+), 61 deletions(-)

diff --git a/java/org/apache/catalina/webresources/DirResourceSet.java 
b/java/org/apache/catalina/webresources/DirResourceSet.java
index b6da202b5c..074839312b 100644
--- a/java/org/apache/catalina/webresources/DirResourceSet.java
+++ b/java/org/apache/catalina/webresources/DirResourceSet.java
@@ -45,8 +45,6 @@ public class DirResourceSet extends AbstractFileResourceSet 
implements WebResour
 
     private static final Log log = LogFactory.getLog(DirResourceSet.class);
 
-    private boolean caseSensitive = true;
-
     private Map<String,ResourceLock> resourceLocksByPath = new HashMap<>();
     private Object resourceLocksByPathLock = new Object();
 
@@ -322,7 +320,6 @@ public class DirResourceSet extends AbstractFileResourceSet 
implements WebResour
     @Override
     protected void initInternal() throws LifecycleException {
         super.initInternal();
-        caseSensitive = isCaseSensitive();
         // Is this an exploded web application?
         if (getWebAppMount().equals("")) {
             // Look for a manifest
@@ -338,65 +335,16 @@ public class DirResourceSet extends 
AbstractFileResourceSet implements WebResour
     }
 
 
-    /*
-     * Determines if this ResourceSet is based on a case sensitive file system 
or not.
-     *
-     * File systems are usually case sensitive or not. Windows, via the 
command 'fsutil.exe file setCaseSensitiveInfo
-     * <path> enable', may be case sensitive in some directories and case 
insensitive in others.
-     *
-     * If this method incorrectly determines that the DirResourceSet is case 
sensitive, the file locking mechanism that
-     * ensures write operations are performed atomically will not operate 
correctly. If this method incorrectly
-     * determines that the DirResourceSet is case insensitive, there is a 
small performance penalty for writes.
-     *
-     * Given the above, this method only reports the file system as case 
sensitive if no indication of case
-     * insensitivity is detected. This does mean that Windows based 
DirResourceSet instances will be reported as case
-     * insensitive even all of the directories in the DirResourceSet have been 
configured as case sensitive.
-     */
-    private boolean isCaseSensitive() {
-        try {
-            String canonicalPath = getFileBase().getCanonicalPath();
-            /*
-             * If any lower case characters are found in the canonical file 
name formed by converting the test file name
-             * to upper case, the underlying file system must be, at least in 
part, case insensitive.
-             */
-            File upper = new File(canonicalPath.toUpperCase(Locale.ENGLISH));
-            String upperCanonicalPath = upper.getCanonicalPath();
-            char[] upperCharacters = upperCanonicalPath.toCharArray();
-            for (char c : upperCharacters) {
-                if (Character.isLowerCase(c)) {
-                    return false;
-                }
-            }
-
-            /*
-             * If any upper case characters are found in the canonical file 
name formed by converting the test file name
-             * to lower case, the underlying file system must be, at least in 
part, case insensitive.
-             */
-            File lower = new File(canonicalPath.toLowerCase(Locale.ENGLISH));
-            String lowerCanonicalPath = lower.getCanonicalPath();
-            char[] lowerCharacters = lowerCanonicalPath.toCharArray();
-            for (char c : lowerCharacters) {
-                if (Character.isUpperCase(c)) {
-                    return false;
-                }
-            }
-
-            return true;
-        } catch (IOException ioe) {
-            log.warn(sm.getString("dirResourceSet.isCaseSensitive.fail", 
getFileBase().getAbsolutePath()), ioe);
-        }
-
-        return false;
-    }
-
-
     private String getLockKey(String path) {
-        // Normalize path to ensure that the same key is used for the same 
path.
-        String normalisedPath = RequestUtil.normalize(path);
-        if (caseSensitive) {
-            return normalisedPath;
-        }
-        return normalisedPath.toLowerCase(Locale.ENGLISH);
+        /*
+         * Normalize path to ensure that the same key is used for the same 
path. Always convert path to lower case as
+         * the file system may be case insensitive. A minor performance 
improvement is possible by removing the
+         * conversion to lower case for case sensitive file systems but 
confirming that all the directories within a
+         * DirResourceSet are case sensitive is much harder than it might 
first appear due to various edge cases. In
+         * particular, Windows can make individual directories case sensitive 
and File.getCanonicalPath() doesn't return
+         * the canonical file name on Linux for some case insensitive file 
systems (such as mounted Windows shares).
+         */
+        return RequestUtil.normalize(path).toLowerCase(Locale.ENGLISH);
     }
 
 


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

Reply via email to