Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
cvs-plugin part of fix for JENKINS-23234: update after review: add cu…
…rlies for if, simplify and remove references to issue in log output and comments, use listener.error in case of exception when checking for symlink.
  • Loading branch information
James Coleman committed Nov 10, 2014
1 parent 8574c85 commit 273ee9b
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/main/java/hudson/scm/AbstractCvs.java
Expand Up @@ -325,8 +325,7 @@ private static void pruneEmptyDirectories(File d, final TaskListener listener) t
}

if (isSymLink(kid,listener)) {
// JENKINS-23234: jenkins cvs update hang when recursive symlink in directory
listener.getLogger().println("JENKINS-23234 pruneEmptyDirectories prevent potential infinate loop, ignoring symlink:" + kid);
listener.getLogger().println("pruneEmptyDirectories. prevent potential infinate loop, ignoring symlink:" + kid);
continue;
}

Expand Down Expand Up @@ -855,8 +854,7 @@ private void cleanup(File directory, AdminHandler adminHandler) throws IOExcepti

for (File innerFile : innerFiles) {
if (isSymLink(innerFile,listener)) {
// JENKINS-23234: jenkins cvs update hang when recursive symlink in directory
listener.getLogger().println("JENKINS-23234 cleanup prevent potential infinate loop, ignoring symlink:" + innerFile);
listener.getLogger().println("cleanup. prevent potential infinate loop, ignoring symlink:" + innerFile);
continue;
}
if (innerFile.isDirectory() && !innerFile.getName().equals("CVS")) {
Expand Down Expand Up @@ -892,17 +890,14 @@ private Map<CvsRepository, List<CvsFile>> calculateWorkspaceState(final FilePath
}

/**
* Return true if file is a symbolic link.
* Symbolic links are ignored by the major cvs clients.
* Symbolic link to dir within cvs tree can cause infinate loop of cvs update following symlink.
* Solution when recursive check is directory a symlink and ignore it if so.
* JENKINS-23234: jenkins cvs update hang when recursive symlink in directory
* @param file name of file/dir/symlink to test
* @return true if file is actually a symbolic link, false if not
* Check if the given file is a symbolic link. Useful for preventing CSV recursing into directories infinitely.
* @param file name of the file to test
* @return whether the file if believed to be a symlink or not
*/
public static boolean isSymLink(File file, final TaskListener listener) {
if (file == null)
if (file == null) {
return false;
}
try {
File canon;
if (file.getParent() == null) {
Expand All @@ -913,7 +908,8 @@ public static boolean isSymLink(File file, final TaskListener listener) {
}
return !canon.getCanonicalFile().equals(canon.getAbsoluteFile());
} catch (IOException ex) {
listener.getLogger().println("JENKINS-23234 isSymLink exception:" + ex);
ex.printStackTrace(listener.error("Ignoring exception when checking for symlink. file:" +
file + " exception:" + ex.getMessage()));
}
return false;
}
Expand Down Expand Up @@ -975,8 +971,7 @@ public List<CvsFile> buildFileList(final File moduleLocation, final String prefi
if (!isSymLink(file,listener)) {
fileList.addAll(buildFileList(file, prefix + "/" + file.getName()));
} else {
// JENKINS-23234: jenkins cvs update hang when recursive symlink in directory
listener.getLogger().println("JENKINS-23234 buildFileList prevent potential infinate loop, ignoring symlink:" + file);
listener.getLogger().println("buildFileList. prevent potential infinate loop, ignoring symlink:" + file);
}
}
}
Expand Down

0 comments on commit 273ee9b

Please sign in to comment.