Browse Source

Fix symlink check

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274833 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
729aa048f3
1 changed files with 39 additions and 0 deletions
  1. +39
    -0
      src/main/org/apache/tools/ant/DirectoryScanner.java

+ 39
- 0
src/main/org/apache/tools/ant/DirectoryScanner.java View File

@@ -705,6 +705,10 @@ public class DirectoryScanner
}

if (myfile.exists()) {
if (!followSymlinks && isSymlink(basedir, currentelement)) {
continue;
}

if (myfile.isDirectory()) {
if (isIncluded(currentelement)
&& currentelement.length() > 0) {
@@ -1192,4 +1196,39 @@ public class DirectoryScanner
}
return null;
}

/**
* Do we have to traverse a symlink when trying to reach path from
* basedir?
* @since Ant 1.6
*/
private boolean isSymlink(File base, String path) {
return isSymlink(base, SelectorUtils.tokenizePath(path));
}

/**
* Do we have to traverse a symlink when trying to reach path from
* basedir?
* @since Ant 1.6
*/
private boolean isSymlink(File base, Vector pathElements) {
if (pathElements.size() > 0) {
String current = (String) pathElements.remove(0);
try {
if (fileUtils.isSymbolicLink(base, current)) {
return true;
} else {
base = new File(base, current);
return isSymlink(base, pathElements);
}
} catch (IOException ioe) {
String msg = "IOException caught while checking "
+ "for links, couldn't get cannonical path!";
// will be caught and redirected to Ant's logging system
System.err.println(msg);
return false;
}
}
return false;
}
}

Loading…
Cancel
Save