Skip to content

Commit

Permalink
cvs-plugin part of fix for JENKINS-23234: jenkins cvs update hang whe…
Browse files Browse the repository at this point in the history
…n recursive symlink in directory. ignore symlinks like the major cvs clients.
  • Loading branch information
James Coleman committed Jun 11, 2014
1 parent 7fa519e commit 6020905
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion src/main/java/hudson/scm/AbstractCvs.java
Expand Up @@ -74,6 +74,8 @@
import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

Expand Down Expand Up @@ -321,6 +323,13 @@ private static void pruneEmptyDirectories(File d) throws IOException {
// not CVS-controlled, ignore
continue;
}

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

pruneEmptyDirectories(kid);
File[] subkids = kid.listFiles();
if (subkids != null && subkids.length == 1) {
Expand Down Expand Up @@ -843,7 +852,13 @@ private void cleanup(File directory, AdminHandler adminHandler) throws IOExcepti

File[] innerFiles = directory.listFiles();
if (null != innerFiles) {

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

/**
* 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
*/
public static boolean isSymLink(File file) {
if (file == null)
return false;
try {
File canon;
if (file.getParent() == null) {
canon = file;
} else {
File canonDir = file.getParentFile().getCanonicalFile();
canon = new File(canonDir, file.getName());
}
return !canon.getCanonicalFile().equals(canon.getAbsoluteFile());
} catch (IOException ex) {
System.err.println("isSymLink exception:" + ex);
}
return false;
}


private List<CvsFile> getCvsFiles(final FilePath workspace, final CvsModule module, final boolean flatten,
final EnvVars envVars)
throws IOException, InterruptedException {
Expand Down Expand Up @@ -928,7 +971,12 @@ public List<CvsFile> buildFileList(final File moduleLocation, final String prefi
if (directoryFiles != null) {
for (File file : directoryFiles) {
if (file.isDirectory()) {
fileList.addAll(buildFileList(file, prefix + "/" + file.getName()));
if (!isSymLink(file)) {
fileList.addAll(buildFileList(file, prefix + "/" + file.getName()));
} else {
// JENKINS-23234: jenkins cvs update hang when recursive symlink in directory
System.err.println("buildFileList prevent potential infinate loop, ignoring symlink:" + file);
}
}
}
}
Expand Down

0 comments on commit 6020905

Please sign in to comment.