How do I avoid symlinks using an Ant FileSet?
I have a directory tree that includes a symlink to . (the current directory). When I attempt to iterate over this using an Ant FileSet, I get the following error:
Caught error while checking for symbolic links
at org.apache.tools.ant.DirectoryScanner.causesIllegalSymlinkLoop(DirectoryScanner.java:1859)
The code that I am using to generate the scanner is:
FileSet files = new FileSet();
Project project = new Project();
project.setBasedir( dir );
files.setProject( project );
files.setDir( project.getBaseDir() );开发者_高级运维
files.getDirectoryScanner().setFollowSymlinks( false );
for( Iterator iter = files.iterator(); iter.hasNext(); ) {}
You can set followsymlinks
property of FileSet
to false
as documented here.
You're setting the 'not-follow' in the wrong place. Use
files.setFollowSymlinks( false );
instead of
files.getDirectoryScanner().setFollowSymlinks( false );
The code you posted will set 'not-follow symlinks' only when scanning below the top-level directory of the fileset. Symlinks in the top-level directory will still be followed.
Its not clear from what you have posted precisely what's causing an IOException to be raised in the causesIllegalSymlinkLoop()
method (that exception is being caught at line 1859).
But if you set not-follow on the fileset rather than its internal directory scanner, the method will not be called at all.
精彩评论