From d61c41640d8da8db162c892b39003159e0eab05e Mon Sep 17 00:00:00 2001 From: Antoine Levy-Lambert Date: Fri, 22 Aug 2003 11:23:48 +0000 Subject: [PATCH] Fixes unsensitive searches on case sensitive remote file systems git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275130 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/ant/taskdefs/optional/net/FTP.java | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java index 738510512..b0c8636f6 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java @@ -660,17 +660,32 @@ public class FTP this.client = parent.client; Vector pathElements = SelectorUtils.tokenizePath(path); try { - this.client.changeWorkingDirectory(parent.getAbsolutePath()); + boolean result = this.client.changeWorkingDirectory(parent.getAbsolutePath()); + //this should not happen, except if parent has been deleted by another process + if (!result) { + return; + } this.curpwd = parent.getAbsolutePath(); } catch (IOException ioe) { throw new BuildException("could not change working dir to " + parent.curpwd); } for (int fcount = 0; fcount < pathElements.size() - 1; fcount++) { + String currentPathElement = (String) pathElements.elementAt(fcount); try { - this.client.changeWorkingDirectory((String) pathElements.elementAt(fcount)); + boolean result = this.client.changeWorkingDirectory(currentPathElement); + if (!result && !isCaseSensitive() + && (remoteSystemCaseSensitive || !remoteSensitivityChecked)) { + currentPathElement = findPathElementCaseUnsensitive(this.curpwd, + currentPathElement); + if (currentPathElement == null) { + return; + } + } else if (!result) { + return; + } this.curpwd = this.curpwd + remoteFileSep - + (String) pathElements.elementAt(fcount); + + currentPathElement; } catch (IOException ioe) { throw new BuildException("could not change working dir to " + (String) pathElements.elementAt(fcount) @@ -682,6 +697,27 @@ public class FTP FTPFile [] theFiles = listFiles(this.curpwd); this.ftpFile = getFile(theFiles, lastpathelement); } + /** + * find a file in a directory in case unsensitive way + * @param parentPath where we are + * @param soughtPathElement what is being sought + * @return the first file found or null if not found + */ + private String findPathElementCaseUnsensitive(String parentPath, + String soughtPathElement) { + // we are already in the right path, so the second parameter + // is false + FTPFile[] theFiles = listFiles(parentPath, false); + if (theFiles == null) { + return null; + } + for (int icounter = 0; icounter < theFiles.length; icounter++) { + if (theFiles[icounter].getName().equalsIgnoreCase(soughtPathElement)) { + return theFiles[icounter].getName(); + } + } + return null; + } /** * find out if the file exists * @return true if the file exists