Index: src/main/org/apache/tools/ant/DirectoryScanner.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- src/main/org/apache/tools/ant/DirectoryScanner.java (date 1531197234000) +++ src/main/org/apache/tools/ant/DirectoryScanner.java (date 1540368990000) @@ -1258,6 +1258,17 @@ final String name = vpath + newFile; final TokenizedPath newPath = new TokenizedPath(path, newFile); final File file = new File(dir, newFile); + + try { + if (FileUtils.getFileUtils().isLeadingPath(file.getAbsoluteFile(), + dir.getAbsoluteFile(), true)) { + continue; + } + } catch (IOException e) { + System.err.println("Failed to get canoncial paths to determine " + + "if filesyste loop exists, continuning"); + } + final String[] children = file.list(); if (children == null || (children.length == 0 && file.isFile())) { if (isIncluded(newPath)) { Index: src/etc/testcases/core/directoryscanner.xml IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- src/etc/testcases/core/directoryscanner.xml (date 1531197234000) +++ src/etc/testcases/core/directoryscanner.xml (date 1540321168000) @@ -38,4 +38,9 @@ + + + + + Index: src/tests/junit/org/apache/tools/ant/DirectoryScannerTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- src/tests/junit/org/apache/tools/ant/DirectoryScannerTest.java (date 1531197234000) +++ src/tests/junit/org/apache/tools/ant/DirectoryScannerTest.java (date 1540287919000) @@ -132,6 +132,20 @@ new String[] {"alpha/beta/gamma"}); } + @Test + public void testAllowRecursiveSymlinks() { + + assumeTrue("Current system does not support Symlinks", supportsSymlinks); + + buildRule.getProject().executeTarget("symlink-nested-setup"); + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] {"alpha/beta/gamma/"}); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha/beta/gamma"}); + } + @Test public void testProhibitSymlinks() { assumeTrue("Current system does not support Symlinks", supportsSymlinks); Index: src/main/org/apache/tools/ant/taskdefs/Delete.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- src/main/org/apache/tools/ant/taskdefs/Delete.java (date 1531197234000) +++ src/main/org/apache/tools/ant/taskdefs/Delete.java (date 1540321373000) @@ -19,6 +19,7 @@ package org.apache.tools.ant.taskdefs; import java.io.File; +import java.io.IOException; import java.util.Arrays; import java.util.Comparator; import java.util.Iterator; @@ -771,7 +772,16 @@ } for (String s : list) { File f = new File(d, s); - if (f.isDirectory()) { + + boolean isSymlink = false; + + try { + isSymlink = SYMLINK_UTILS.isSymbolicLink(f); + } catch (IOException e) { + log("Failed to check directory is symlink, assuming that it is not"); + } + + if (!isSymlink && f.isDirectory()) { removeDir(f); } else { log("Deleting " + f.getAbsolutePath(), quiet ? Project.MSG_VERBOSE : verbosity);