Browse Source

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
master
Antoine Levy-Lambert 22 years ago
parent
commit
d61c41640d
1 changed files with 39 additions and 3 deletions
  1. +39
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java

+ 39
- 3
src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java View File

@@ -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


Loading…
Cancel
Save