protected String getPhysicalName()

in core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFileSystemView.java [184:261]


    protected String getPhysicalName(final String rootDir,
            final String currDir, final String fileName,
            final boolean caseInsensitive) {

        // normalize root dir
        String normalizedRootDir = normalizeSeparateChar(rootDir);
        normalizedRootDir = appendSlash(normalizedRootDir);

        // normalize file name
        String normalizedFileName = normalizeSeparateChar(fileName);
        String result;
        
        // if file name is relative, set resArg to root dir + curr dir
        // if file name is absolute, set resArg to root dir
        if (normalizedFileName.charAt(0) != '/') {
            // file name is relative
            String normalizedCurrDir = normalize(currDir, "/");

            result = normalizedRootDir + normalizedCurrDir.substring(1);
        } else {
            result = normalizedRootDir;
        }

        // strip last '/'
        result = trimTrailingSlash(result);

        // replace ., ~ and ..
        // in this loop resArg will never end with '/'
        StringTokenizer st = new StringTokenizer(normalizedFileName, "/");
        while (st.hasMoreTokens()) {
            String tok = st.nextToken();

            // . => current directory
            if (tok.equals(".")) {
                // ignore and move on
            } else if (tok.equals("..")) {
                // .. => parent directory (if not root)
                if (result.startsWith(normalizedRootDir)) {
                    int slashIndex = result.lastIndexOf('/');
                    if (slashIndex != -1) {
                        result = result.substring(0, slashIndex);
                    }
                }
            } else if (tok.equals("~")) {
                // ~ => home directory (in this case the root directory)
                result = trimTrailingSlash(normalizedRootDir);
                continue;
            } else {
                // token is normal directory name
                
                if(caseInsensitive) {
                    // we're case insensitive, find a directory with the name, ignoring casing
                    File[] matches = new File(result)
                            .listFiles(new NameEqualsFileFilter(tok, true));
    
                    if (matches != null && matches.length > 0) {
                        // found a file matching tok, replace tok for get the right casing
                        tok = matches[0].getName();
                    }
                }

                result = result + '/' + tok;
    
            }
        }

        // add last slash if necessary
        if ((result.length()) + 1 == normalizedRootDir.length()) {
            result += '/';
        }

        // make sure we did not end up above root dir
        if (!result.startsWith(normalizedRootDir)) {
            result = normalizedRootDir;
        }

        return result;
    }