Skip to content
Permalink
Browse files
Merge pull request #57 from jglick/symlinks-JENKINS-20546
[JENKINS-20546] Preserve symlinks when copying artifacts
  • Loading branch information
ikedam committed Feb 14, 2015
2 parents 68a64c0 + 085c4c9 commit 5cfa07b8bac9caeb664b9c99c1891e206a89fd3d
@@ -6,6 +6,7 @@
import hudson.model.Fingerprint;
import hudson.model.FingerprintMap;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.os.PosixException;
import hudson.tasks.Fingerprinter.FingerprintAction;
import hudson.util.IOException2;
@@ -67,6 +68,11 @@ public int copyAll(FilePath srcDir, String filter, String excludes, FilePath tar

@Override
public void copyOne(FilePath s, FilePath d, boolean fingerprintArtifacts) throws IOException, InterruptedException {
String link = s.readLink();
if (link != null) {
d.symlinkTo(link, /* TODO Copier signature does not offer a TaskListener; anyway this is rarely used */TaskListener.NULL);
return;
}
try {
md5.reset();
DigestOutputStream out =new DigestOutputStream(d.write(),md5);
@@ -85,7 +85,7 @@
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.google.common.collect.Sets;

import static org.junit.Assert.assertTrue;
import org.jvnet.hudson.test.TestBuilder;

/*
// classes used only in testQueueItemAuthenticator
@@ -1662,6 +1662,28 @@ public void testFilePermission() throws Exception {
assertEquals(0755, w.child("artifactWithExecuteInSubdir.txt").mode() & 0777);
}
}

@Bug(20546)
public void testSymlinks() throws Exception {
FreeStyleProject p1 = createFreeStyleProject("p1");
p1.getBuildersList().add(new TestBuilder() {
@Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
build.getWorkspace().child("plain").write("text", null);
build.getWorkspace().child("link1").symlinkTo("plain", listener);
build.getWorkspace().child("link2").symlinkTo("nonexistent", listener);
return true;
}
});
p1.getPublishersList().add(new ArtifactArchiver("**", "", false, false));
buildAndAssertSuccess(p1);
FreeStyleProject p2 = createFreeStyleProject("p2");
p2.getBuildersList().add(CopyArtifactUtil.createCopyArtifact("p1", null, new StatusBuildSelector(true), null, "", false, false, true));
FreeStyleBuild b = buildAndAssertSuccess(p2);
FilePath ws = b.getWorkspace();
assertEquals("text", ws.child("plain").readToString());
assertEquals("plain", ws.child("link1").readLink());
assertEquals("nonexistent", ws.child("link2").readLink());
}

/* This test is available only for Jenkins >= 1.521.
* As I do not upgrade target Jenkins version to preserve compatibility

0 comments on commit 5cfa07b

Please sign in to comment.