Skip to content
Browse files

[FIXED JENKINS-17681] Do not try to call resolveSymlink on a nonexist…

…ent link as you will just get an IOException, breaking peephole permalinks in some Windows environments.
  • Loading branch information
jglick committed May 2, 2013
1 parent 00d5e38 commit 3c2b50ecfe1c58f64b32d30a3f96e647671f7d03
@@ -58,6 +58,9 @@
<li class=bug>
Display Name is not shown.
(<a href="">issue 17715</a>)
<li class='major bug'>
Symlink handling problem with build permalinks on Windows.
(<a href="">issue 17681</a>)
<li class=bug>
List views missing a required field were unloadable.
(<a href="">issue 15309</a>)
@@ -1200,6 +1200,10 @@ public static String resolveSymlink(File link) throws InterruptedException, IOEx
} catch (ClassNotFoundException x3) {
assert false : x3; // should be Java 7+ here
if (x2.getClass().getName().equals("java.nio.file.FileSystemException")) {
// Thrown ("Incorrect function.") on JDK 7u21 in Windows 2012 when called on a non-symlink, rather than NotLinkException, contrary to documentation. Maybe only when not on NTFS?
return null;
if (x2 instanceof IOException) {
throw (IOException) x2;
@@ -17,6 +17,7 @@
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;

@@ -143,6 +144,12 @@ protected void updateCache(@Nonnull Job<?,?> job, @Nullable Run<?,?> b) {

// File.exists returns false for a link with a missing target, so for Java 6 compatibility we have to use this circuitous method to see if it was created.
private static boolean exists(File link) {
File[] kids = link.getParentFile().listFiles();
return kids != null && Arrays.asList(kids).contains(link);

static String readSymlink(File cache) throws IOException, InterruptedException {
String target = Util.resolveSymlink(cache);
if (target==null && cache.exists()) {
@@ -158,7 +165,8 @@ static void writeSymlink(File cache, String target) throws IOException, Interrup
File tmp = new File(cache.getPath()+".tmp");
try {
if (Util.resolveSymlink(tmp)==null) {
// Avoid calling resolveSymlink on a nonexistent file as it will probably throw an IOException:
if (!exists(tmp) || Util.resolveSymlink(tmp)==null) {
// symlink not supported. use a regular file
AtomicFileWriter cw = new AtomicFileWriter(cache);
try {

0 comments on commit 3c2b50e

Please sign in to comment.