Browse Source

Go on working on the followsymlinks support in the FTP task.

The scanner was working previously, but the retrieving of links was not working
because the followsymlinks attribute was not passed through.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275089 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 22 years ago
parent
commit
c16e1955f1
4 changed files with 77 additions and 2 deletions
  1. +26
    -0
      src/etc/testcases/taskdefs/optional/net/ftp.xml
  2. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
  3. +15
    -0
      src/main/org/apache/tools/ant/types/AbstractFileSet.java
  4. +34
    -0
      src/testcases/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java

+ 26
- 0
src/etc/testcases/taskdefs/optional/net/ftp.xml View File

@@ -18,6 +18,12 @@
<fileset dir="${tmp.get.dir}" id="fileset-destination-without-selector"> <fileset dir="${tmp.get.dir}" id="fileset-destination-without-selector">
<include name="alpha/**"/> <include name="alpha/**"/>
</fileset> </fileset>
<fileset dir="${tmp.get.dir}" id="fileset-destination-followsymlinks" followsymlinks="true">
<include name="alpha/**"/>
</fileset>
<fileset dir="${tmp.get.dir}" id="fileset-destination-nofollowsymlinks" followsymlinks="false">
<include name="alpha/**"/>
</fileset>
<target name="setup"> <target name="setup">
<mkdir dir="${tmp.get.dir}"/> <mkdir dir="${tmp.get.dir}"/>
<mkdir dir="${tmp.dir}/alpha/beta/gamma"/> <mkdir dir="${tmp.dir}/alpha/beta/gamma"/>
@@ -47,6 +53,26 @@
<symlink link="${tmp.dir}/alpha/beta" resource="${tmp.dir}/epsilon"/> <symlink link="${tmp.dir}/alpha/beta" resource="${tmp.dir}/epsilon"/>
<touch file="${tmp.dir}/alpha/beta/gamma/gamma.xml"/> <touch file="${tmp.dir}/alpha/beta/gamma/gamma.xml"/>
</target> </target>
<target name="ftp-get-directory-symbolic-link" depends="symlink-setup">
<ftp action="get"
server="${ftp.host}"
userid="${ftp.user}"
password="${ftp.password}"
remotedir="${tmp.dir}"
>
<fileset refid="fileset-destination-followsymlinks"/>
</ftp>
</target>
<target name="ftp-get-directory-no-symbolic-link" depends="symlink-setup">
<ftp action="get"
server="${ftp.host}"
userid="${ftp.user}"
password="${ftp.password}"
remotedir="${tmp.dir}"
>
<fileset refid="fileset-destination-nofollowsymlinks"/>
</ftp>
</target>
<target name="symlink-file-setup" depends="setup"> <target name="symlink-file-setup" depends="setup">
<delete file="${tmp.dir}/alpha/beta/gamma/gamma.xml"/> <delete file="${tmp.dir}/alpha/beta/gamma/gamma.xml"/>
<symlink link="${tmp.dir}/alpha/beta/gamma/gamma.xml" <symlink link="${tmp.dir}/alpha/beta/gamma/gamma.xml"


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

@@ -248,7 +248,6 @@ public class FTP
ftp.changeToParentDirectory(); ftp.changeToParentDirectory();
return; return;
} }

for (int i = 0; i < newfiles.length; i++) { for (int i = 0; i < newfiles.length; i++) {
FTPFile file = newfiles[i]; FTPFile file = newfiles[i];
if (!file.getName().equals(".") if (!file.getName().equals(".")
@@ -662,7 +661,7 @@ public class FTP
*/ */
protected int transferFiles(FTPClient ftp, FileSet fs) protected int transferFiles(FTPClient ftp, FileSet fs)
throws IOException, BuildException { throws IOException, BuildException {
FileScanner ds;
DirectoryScanner ds;


if (action == SEND_FILES) { if (action == SEND_FILES) {
ds = fs.getDirectoryScanner(getProject()); ds = fs.getDirectoryScanner(getProject());
@@ -674,6 +673,7 @@ public class FTP
} }
ds = new FTPDirectoryScanner(ftp); ds = new FTPDirectoryScanner(ftp);
fs.setupDirectoryScanner(ds, getProject()); fs.setupDirectoryScanner(ds, getProject());
ds.setFollowSymlinks(fs.isFollowSymlinks());
ds.scan(); ds.scan();
} }




+ 15
- 0
src/main/org/apache/tools/ant/types/AbstractFileSet.java View File

@@ -329,6 +329,21 @@ public abstract class AbstractFileSet extends DataType implements Cloneable,
this.followSymlinks = followSymlinks; this.followSymlinks = followSymlinks;
} }


/**
* find out if the fileset wants to follow symbolic links
*
* @return flag indicating whether or not symbolic links should be followed
*
* @since ant 1.6
*/
public boolean isFollowSymlinks() {
if (isReference()) {
return getRef(getProject()).isFollowSymlinks();
} else {
return followSymlinks;
}
}

/** /**
* sets the name used for this datatype instance. * sets the name used for this datatype instance.
*/ */


+ 34
- 0
src/testcases/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java View File

@@ -226,6 +226,40 @@ public class FTPTest extends BuildFileTest{
dsSource.scan(); dsSource.scan();
compareFiles(dsSource, sortedDestinationFiles, sortedDestinationDirectories); compareFiles(dsSource, sortedDestinationFiles, sortedDestinationDirectories);
} }
public void testGetFollowSymlinksTrue() {
if (!supportsSymlinks) {
return;
}
if (!loginSuceeded) {
return;
}
if (!changeRemoteDir(remoteTmpDir)) {
return;
}
getProject().executeTarget("ftp-get-directory-symbolic-link");
FileSet fsDestination = (FileSet) getProject().getReference("fileset-destination-without-selector");
DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(getProject());
dsDestination.scan();
compareFiles(dsDestination, new String[] {"alpha/beta/gamma/gamma.xml"},
new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
}
public void testGetFollowSymlinksFalse() {
if (!supportsSymlinks) {
return;
}
if (!loginSuceeded) {
return;
}
if (!changeRemoteDir(remoteTmpDir)) {
return;
}
getProject().executeTarget("ftp-get-directory-no-symbolic-link");
FileSet fsDestination = (FileSet) getProject().getReference("fileset-destination-without-selector");
DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(getProject());
dsDestination.scan();
compareFiles(dsDestination, new String[] {},
new String[] {});
}
public void testAllowSymlinks() { public void testAllowSymlinks() {
if (!supportsSymlinks) { if (!supportsSymlinks) {
return; return;


Loading…
Cancel
Save