Skip to content

Commit

Permalink
[FIXED JENKINS-20546] Preserve symlinks when copying artifacts.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Feb 6, 2015
1 parent 68a64c0 commit 085c4c9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 23 additions & 1 deletion src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 085c4c9

Please sign in to comment.