提交 2f781863 编写于 作者: K Kohsuke Kawaguchi

Massaging the fix.

- ID_FORMATTER is time zone sensitive, so comparing against # of
  milliseconds since the epoch won't be portable.

- resolveSymlink can return a relative path.
上级 8f6a2229
......@@ -1094,6 +1094,21 @@ public class Util {
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>
......
......@@ -342,10 +342,9 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
try {
if(Util.isSymlink(buildDir)) {
// "Util.resolveSymlink(file)" resolves NTFS symlinks.
String resolvedSymlink = Util.resolveSymlink(buildDir);
if(resolvedSymlink != null) {
buildDir = new File(resolvedSymlink);
}
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
......
......@@ -30,6 +30,7 @@ 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;
......@@ -92,13 +93,11 @@ public class RunTest {
public void testParseTimestampFromBuildDir() throws Exception {
//Assume.assumeTrue(!Functions.isWindows() || (NTFS && JAVA7) || ...);
String buildDateTime = "2012-12-21_14-02-28";
long buildTimestamp = 1356091348000L;
String buildDateTime = "2012-12-21_04-02-28";
int buildNumber = 155;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamTaskListener l = new StreamTaskListener(baos, Charset.defaultCharset());
StreamTaskListener l = StreamTaskListener.fromStdout();
File tempDir = Util.createTempDir();
File buildDir = new File(tempDir, buildDateTime);
assertEquals(true, buildDir.mkdir());
......@@ -108,7 +107,8 @@ public class RunTest {
buildDir.mkdir();
Util.createSymlink(tempDir, buildDir.getAbsolutePath(), buildDirSymLink.getName(), l);
assertEquals(buildTimestamp, Run.parseTimestampFromBuildDir(buildDirSymLink));
long time = Run.parseTimestampFromBuildDir(buildDirSymLink);
assertEquals(buildDateTime, Run.ID_FORMATTER.get().format(new Date(time)));
} finally {
Util.deleteRecursive(tempDir);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册