Chenjp commented on PR #820:
URL: https://github.com/apache/tomcat/pull/820#issuecomment-2665144518

   Updated.
   Incorrect results of current source code V0 received:
   ```
   V0: Case sensitivity of 'D:\case-sensitivity-verification' is false
   V1: Case sensitivity of 'D:\case-sensitivity-verification' is false
   V0: Case sensitivity of 
'D:\case-sensitivity-verification\case-insensitive-dir' is false
   V1: Case sensitivity of 
'D:\case-sensitivity-verification\case-insensitive-dir' is false
   V0: Case sensitivity of 
'D:\case-sensitivity-verification\case-sensitive-dir' is false
   V1: Case sensitivity of 
'D:\case-sensitivity-verification\case-sensitive-dir' is true
   V0: Case sensitivity of 
'D:\case-sensitivity-verification\case-sensitive-dir\case-insensitive-dir' is 
true
   V1: Case sensitivity of 
'D:\case-sensitivity-verification\case-sensitive-dir\case-insensitive-dir' is 
false
   V0: Case sensitivity of 'D:\case-sensitivity-verification\大小写不敏感目录' is false
   V1: Case sensitivity of 'D:\case-sensitivity-verification\大小写不敏感目录' is false
   V0: Case sensitivity of 'D:\case-sensitivity-verification\大小写敏感目录' is false
   V1: Case sensitivity of 'D:\case-sensitivity-verification\大小写敏感目录' is true
   ```
   
   See java source code:
   ```java
   
   import java.io.File;
   import java.io.IOException;
   import java.util.Locale;
   
   /**
    *
    */
   public class FileSystemCaseSensitivity {
   
       /**
        * @param args
        */
       public static void main(String[] args) throws IOException {
           printCaseSensitivity(new File("d:\\case-sensitivity-verification"));
       }
   
       public static void printCaseSensitivity(File dir) throws IOException {
           if (dir.isDirectory()) {
               System.out.println(
                       String.format("V0: Case sensitivity of '%s' is %b", 
dir.getCanonicalPath(), isCaseSensitive0(dir)));
               System.out.println(
                       String.format("V1: Case sensitivity of '%s' is %b", 
dir.getCanonicalPath(), isCaseSensitive1(dir)));
               for (File subdir : dir.listFiles()) {
                   printCaseSensitivity(subdir);
               }
           }
       }
   
       public static boolean isCaseSensitive0(File dir) {
           try {
               String canonicalPath = dir.getCanonicalPath();
               File upper = new File(canonicalPath.toUpperCase(Locale.ENGLISH));
               if (!canonicalPath.equals(upper.getCanonicalPath())) {
                   return true;
               }
               File lower = new File(canonicalPath.toLowerCase(Locale.ENGLISH));
               if (!canonicalPath.equals(lower.getCanonicalPath())) {
                   return true;
               }
               /* Both upper and lower case versions of the current fileBase 
have the same canonical path so the file
                * system must be case insensitive. */
           } catch (IOException ioe) {
               ioe.printStackTrace();
           }
   
           return false;
       }
   
       public static boolean isCaseSensitive1(File dir) {
           try {
               // Some file system (e.g. windows) treat files and directories 
as case insensitive by default, and also
               // support
               // setting case sensitivity per directory. Then we have to 
handle case sensitivity for each directory.
               // Ensure file path contain ENGLISH string, otherwise its upper 
and lower maybe are same.
               dir = dir.getCanonicalFile();
               String lastPartName = ".Tomcat_cs_verify";
               File testFile = new File(dir, lastPartName);
               if (!testFile.exists()) {
                   if (testFile.createNewFile()) {
                       testFile.deleteOnExit();
                   } else {
                       throw new IOException();
                   }
               }
               String canonicalPath = testFile.getCanonicalPath();
               File upper = new File(dir, 
lastPartName.toUpperCase(Locale.ENGLISH));
               if (!upper.getCanonicalPath().equals(canonicalPath)) {
                   return true;
               }
               File lower = new File(dir, 
lastPartName.toLowerCase(Locale.ENGLISH));
               if (!lower.getCanonicalPath().equals(canonicalPath)) {
                   return true;
               }
               /* Both upper and lower case versions of the current fileBase 
have the same canonical path so the file
                * system must be case insensitive. */
           } catch (IOException ioe) {
               ioe.printStackTrace();
           }
           return false;
       }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to