private static boolean checkCaseSymlink ( File file , String pathToTest ) throws PrivilegedActionException { // java.nio.Path.toRealPath(LinkOption.NOFOLLOW_LINKS) in java 7 seems to do what // we are trying to do here //On certain platforms, i.e. iSeries, the path starts with a slash. //Remove this slash before continuing. if ( pathToTest . startsWith ( "/" ) ) pathToTest = pathToTest . substring ( 1 ) ; String [ ] splitPathToTest = pathToTest . split ( "/" ) ; File symLinkTestFile = file ; for ( int i = splitPathToTest . length - 1 ; i >= 0 ; i -- ) { File symLinkParentFile = symLinkTestFile . getParentFile ( ) ; if ( symLinkParentFile == null ) { return false ; } // If the current file isn't a symbolic link, make sure the case matches using the // canonical file. Otherwise get the parents list of files to compare against. if ( ! isSymbolicLink ( symLinkTestFile , symLinkParentFile ) ) { if ( ! getCanonicalFile ( symLinkTestFile ) . getName ( ) . equals ( splitPathToTest [ i ] ) ) { return false ; } } else if ( ! contains ( symLinkParentFile . list ( ) , splitPathToTest [ i ] ) ) { return false ; } symLinkTestFile = symLinkParentFile ; } return true ; }
Test if a file is reached by a path . Handle symbolic links . The test uses the canonical path of the file and does a case sensitive string comparison .