Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-13202] Amelioration of problem: if the platform cannot read …
…symlinks, fall back to visiting them as plain files or directories.
  • Loading branch information
jglick committed Sep 6, 2012
1 parent 597ea1e commit f50316b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 12 additions & 3 deletions core/src/main/java/hudson/util/DirScanner.java
@@ -1,7 +1,6 @@
package hudson.util;

import hudson.Util;
import hudson.model.TaskListener;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.types.FileSet;

Expand Down Expand Up @@ -35,7 +34,12 @@ private void scan(File f, String path, FileVisitor visitor) throws IOException {
if (f.canRead()) {
if (visitor.understandsSymlink()) {
try {
String target = Util.resolveSymlink(f, TaskListener.NULL);
String target;
try {
target = Util.resolveSymlink(f);
} catch (IOException x) { // JENKINS-13202
target = null;
}
if (target!=null) {
visitor.visitSymlink(f,target,path+f.getName());
return;
Expand Down Expand Up @@ -112,7 +116,12 @@ public void scan(File dir, FileVisitor visitor) throws IOException {

if (visitor.understandsSymlink()) {
try {
String target = Util.resolveSymlink(file);
String target;
try {
target = Util.resolveSymlink(file);
} catch (IOException x) { // JENKINS-13202
target = null;
}
if (target!=null) {
visitor.visitSymlink(file,target,f);
continue;
Expand Down
10 changes: 6 additions & 4 deletions core/src/main/java/hudson/util/FileVisitor.java
Expand Up @@ -26,17 +26,19 @@ public abstract class FileVisitor {
* Some visitors can handle symlinks as symlinks. Those visitors should implement
* this method to provide a different handling for symlink.
* <p>
* This method is invoked by those {@link DirScanner}s that can handle symlinks as symlinks
* (not every {@link DirScanner}s are capable of doing that, as proper symlink handling requires
* letting visitors decide whether or not to descend into a symlink directory.
* This method is invoked by those {@link DirScanner}s that can handle symlinks as symlinks.
* (Not every {@link DirScanner}s are capable of doing that, as proper symlink handling requires
* letting visitors decide whether or not to descend into a symlink directory.)
*/
public void visitSymlink(File link, String target, String relativePath) throws IOException {
visit(link,relativePath);
}

/**
* Some visitors can handle symlinks as symlinks. Those visitors should implement
* this method and return true to have callers invoke {@link #visitSymlink(File, String, String)}
* this method and return true to have callers invoke {@link #visitSymlink(File, String, String)}.
* Note that failures to detect or read symlinks on certain platforms
* can cause {@link #visit} to be called on a file which is actually a symlink.
*/
public boolean understandsSymlink() {
return false;
Expand Down

0 comments on commit f50316b

Please sign in to comment.