Browse Source

PR: 33770

Improved FTP task to not fail on hidden directories.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277793 13f79535-47bb-0310-9956-ffa450edef68
master
Jacobus Martinus Kruithof 20 years ago
parent
commit
2d1c5924e5
2 changed files with 29 additions and 10 deletions
  1. +3
    -1
      docs/manual/OptionalTasks/ftp.html
  2. +26
    -9
      src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java

+ 3
- 1
docs/manual/OptionalTasks/ftp.html View File

@@ -262,11 +262,13 @@ patterns of the <code>fileset <br>
href="../CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a> elements to specify href="../CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a> elements to specify
the files to be retrieved, or deleted, or listed, or whose mode you want to change.</p> the files to be retrieved, or deleted, or listed, or whose mode you want to change.</p>
<p> <p>
The attribute <code>followsymlinks</code> of <code>fileset</code> is fully supported on
The attribute <code>followsymlinks</code> of <code>fileset</code> is supported on
local (put) as well as remote (get, chmod, delete) filesets. local (put) as well as remote (get, chmod, delete) filesets.
<em>Before ant 1.6 there was no support of symbolic links in remote filesets. <em>Before ant 1.6 there was no support of symbolic links in remote filesets.
In order to exclude symbolic links (preserve the behavior of ant 1.5.x and older), In order to exclude symbolic links (preserve the behavior of ant 1.5.x and older),
you need to explicitly set <code>followsymlinks</code> to <code>false</code>.</em> you need to explicitly set <code>followsymlinks</code> to <code>false</code>.</em>
On remote filesets hidden files are not checked for being symbolic links. Hidden
files are currently assumed to not be symbolic links.
</p> </p>
<p> <p>
Remote filesets do not support selectors.<br/> Remote filesets do not support selectors.<br/>


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

@@ -194,7 +194,8 @@ public class FTP
try { try {
String cwd = ftp.printWorkingDirectory(); String cwd = ftp.printWorkingDirectory();
// always start from the current ftp working dir // always start from the current ftp working dir

forceRemoteSensitivityCheck();
checkIncludePatterns(); checkIncludePatterns();
clearCaches(); clearCaches();
ftp.changeWorkingDirectory(cwd); ftp.changeWorkingDirectory(cwd);
@@ -210,6 +211,7 @@ public class FTP
* @since ant1.6 * @since ant1.6
*/ */
private void checkIncludePatterns() { private void checkIncludePatterns() {

Hashtable newroots = new Hashtable(); Hashtable newroots = new Hashtable();
// put in the newroots vector the include patterns without // put in the newroots vector the include patterns without
// wildcard tokens // wildcard tokens
@@ -246,6 +248,7 @@ public class FTP
String path = null; String path = null;


if (myfile.exists()) { if (myfile.exists()) {
forceRemoteSensitivityCheck();
if (remoteSensitivityChecked if (remoteSensitivityChecked
&& remoteSystemCaseSensitive && isFollowSymlinks()) { && remoteSystemCaseSensitive && isFollowSymlinks()) {
// cool case, // cool case,
@@ -262,7 +265,6 @@ public class FTP
throw new BuildException(be, getLocation()); throw new BuildException(be, getLocation());
} catch (BuildException be) { } catch (BuildException be) {
isOK = false; isOK = false;

} }
} }
} else { } else {
@@ -509,6 +511,17 @@ public class FTP
} }
return result; return result;
} }
private void forceRemoteSensitivityCheck()
{
if (!remoteSensitivityChecked) {
try {
checkRemoteSensitivity(ftp.listFiles(), ftp.printWorkingDirectory());
} catch (IOException ioe) {
throw new BuildException(ioe, getLocation());
}
}
}
/** /**
* cd into one directory and * cd into one directory and
* list the files present in one directory. * list the files present in one directory.
@@ -763,14 +776,16 @@ public class FTP
if (theFiles != null) { if (theFiles != null) {
theFile = getFile(theFiles, currentElement); theFile = getFile(theFiles, currentElement);
} }
if (!relPath.equals("")) {
relPath = relPath + remoteFileSep;
}
if (theFile == null) { if (theFile == null) {
throw new BuildException("could not find " + currentElement
+ " from " + currentPath);
// hit a hidden file assume not a symlink
relPath = relPath + currentElement;
currentPath = currentPath + remoteFileSep + currentElement;
log("Hidden file " + relPath + " assumed to not be a symlink.", Project.MSG_VERBOSE);
} else { } else {
traversesSymlinks = traversesSymlinks || theFile.isSymbolicLink(); traversesSymlinks = traversesSymlinks || theFile.isSymbolicLink();
if (!relPath.equals("")) {
relPath = relPath + remoteFileSep;
}
relPath = relPath + theFile.getName(); relPath = relPath + theFile.getName();
currentPath = currentPath + remoteFileSep + theFile.getName(); currentPath = currentPath + remoteFileSep + theFile.getName();
} }
@@ -854,6 +869,10 @@ public class FTP
} }
return traversesSymlinks; return traversesSymlinks;
} }
public String toString() {
return "AntFtpFile: "+curpwd+"%"+ftpFile;
}
} }
/** /**
* special class to represent the remote directory itself * special class to represent the remote directory itself
@@ -1273,7 +1292,6 @@ public class FTP
protected int transferFiles(FTPClient ftp, FileSet fs) protected int transferFiles(FTPClient ftp, FileSet fs)
throws IOException, BuildException { throws IOException, BuildException {
DirectoryScanner ds; DirectoryScanner ds;

if (action == SEND_FILES) { if (action == SEND_FILES) {
ds = fs.getDirectoryScanner(getProject()); ds = fs.getDirectoryScanner(getProject());
} else { } else {
@@ -1771,7 +1789,6 @@ public class FTP
protected void getFile(FTPClient ftp, String dir, String filename) protected void getFile(FTPClient ftp, String dir, String filename)
throws IOException, BuildException { throws IOException, BuildException {
OutputStream outstream = null; OutputStream outstream = null;

try { try {
File file = getProject().resolveFile(new File(dir, filename).getPath()); File file = getProject().resolveFile(new File(dir, filename).getPath());




Loading…
Cancel
Save