Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-15587]
The actual fix was in the pull request #675.
  • Loading branch information
kohsuke committed Mar 13, 2013
2 parents f7c9e81 + 2f78186 commit 28bf5d8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -55,6 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=bug>
Fixed a bad interaction between Windows symlinks and build record lazy loading.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-15587">issue 15587</a>)
<li class=rfe>
Remember the lastStable/Failed/Successful/etc builds to avoid eager loading builds.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-16089">issue 16089</a>)
Expand Down
15 changes: 15 additions & 0 deletions core/src/main/java/hudson/Util.java
Expand Up @@ -1140,6 +1140,21 @@ public static String resolveSymlink(File link, TaskListener listener) throws Int
return resolveSymlink(link);
}

/**
* Resolves a symlink to the {@link File} that points to.
*
* @return null
* if the specified file is not a symlink.
*/
public static File resolveSymlinkToFile(File link) throws InterruptedException, IOException {
String target = resolveSymlink(link);
if (target==null) return null;

File f = new File(target);
if (f.isAbsolute()) return f; // absolute symlink
return new File(link.getParentFile(),target); // relative symlink
}

/**
* Resolves symlink, if the given file is a symlink. Otherwise return null.
* <p>
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/hudson/model/Run.java
Expand Up @@ -341,13 +341,21 @@ public void addAction(Action a) {

/*package*/ static long parseTimestampFromBuildDir(File buildDir) throws IOException {
try {
if(Util.isSymlink(buildDir)) {
// "Util.resolveSymlink(file)" resolves NTFS symlinks.
File target = Util.resolveSymlinkToFile(buildDir);
if(target != null)
buildDir = target;
}
// canonicalization to ensure we are looking at the ID in the directory name
// as opposed to build numbers which are used in symlinks
return ID_FORMATTER.get().parse(buildDir.getCanonicalFile().getName()).getTime();
} catch (ParseException e) {
throw new IOException2("Invalid directory name "+buildDir,e);
} catch (NumberFormatException e) {
throw new IOException2("Invalid directory name "+buildDir,e);
} catch (InterruptedException e) {
throw new IOException2("Interrupted while resolving symlink directory "+buildDir,e);
}
}

Expand Down
37 changes: 37 additions & 0 deletions core/src/test/java/hudson/model/RunTest.java
Expand Up @@ -24,10 +24,20 @@

package hudson.model;

import hudson.Util;
import hudson.util.StreamTaskListener;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.TimeZone;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.xml.stream.events.Characters;

import static org.junit.Assert.*;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
Expand Down Expand Up @@ -76,5 +86,32 @@ public String call() throws Exception {
TimeZone.setDefault(origTZ);
}
}


@Bug(15587)
@Test
public void testParseTimestampFromBuildDir() throws Exception {
//Assume.assumeTrue(!Functions.isWindows() || (NTFS && JAVA7) || ...);

String buildDateTime = "2012-12-21_04-02-28";
int buildNumber = 155;

StreamTaskListener l = StreamTaskListener.fromStdout();

File tempDir = Util.createTempDir();
File buildDir = new File(tempDir, buildDateTime);
assertEquals(true, buildDir.mkdir());
File buildDirSymLink = new File(tempDir, Integer.toString(buildNumber));

try {
buildDir.mkdir();

Util.createSymlink(tempDir, buildDir.getAbsolutePath(), buildDirSymLink.getName(), l);
long time = Run.parseTimestampFromBuildDir(buildDirSymLink);
assertEquals(buildDateTime, Run.ID_FORMATTER.get().format(new Date(time)));
} finally {
Util.deleteRecursive(tempDir);
}
}

}

0 comments on commit 28bf5d8

Please sign in to comment.