提交 c49d6b5b 编写于 作者: J Jesse Glick

Use TemporaryFolder to good effect.

Prevents us from leaving behind a temp dir with cyclic symlinks, which breaks JGit’s clean function.
That in turn can cause test builds to break:
https://jenkins.ci.cloudbees.com/job/core/job/jenkins_main_trunk/783/console
Cleaning workspace
FATAL: Could not delete file …/workspace/core/jenkins_main_trunk/core/target/hudson5309354136960541268tmp/c/symlink/c/symlink/c/symlink/…/c/foo.xml
org.eclipse.jgit.api.errors.JGitInternalException: Could not delete file …/workspace/core/jenkins_main_trunk/core/target/hudson5309354136960541268tmp/c/symlink/c/symlink/c/symlink/…/c/foo.xml
	at org.eclipse.jgit.api.CleanCommand.call(CleanCommand.java:137)
	at org.jenkinsci.plugins.gitclient.JGitAPIImpl.clean(JGitAPIImpl.java:305)
	at hudson.plugins.git.GitAPI.clean(GitAPI.java:248)
	at hudson.plugins.git.GitSCM$4.invoke(GitSCM.java:1213)
	at hudson.plugins.git.GitSCM$4.invoke(GitSCM.java:1196)
	at hudson.FilePath$FileCallableWrapper.call(FilePath.java:2236)
	at hudson.remoting.UserRequest.perform(UserRequest.java:118)
	at hudson.remoting.UserRequest.perform(UserRequest.java:48)
	at hudson.remoting.Request$2.run(Request.java:326)
	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
	at java.util.concurrent.FutureTask.run(FutureTask.java:166)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:722)
Caused by: java.io.IOException: Could not delete file …/workspace/core/jenkins_main_trunk/core/target/hudson5309354136960541268tmp/c/symlink/c/symlink/c/symlink/…/c/foo.xml
	at org.eclipse.jgit.util.FileUtils.delete(FileUtils.java:142)
	at org.eclipse.jgit.util.FileUtils.delete(FileUtils.java:126)
	at org.eclipse.jgit.util.FileUtils.delete(FileUtils.java:126)
	…
	at org.eclipse.jgit.util.FileUtils.delete(FileUtils.java:126)
	at org.eclipse.jgit.util.FileUtils.delete(FileUtils.java:126)
	at org.eclipse.jgit.api.CleanCommand.call(CleanCommand.java:132)
	... 14 more
上级 90f3ad5d
......@@ -5,11 +5,10 @@ import hudson.FilePath
import jenkins.security.ConfidentialStoreRule
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import javax.crypto.Cipher
import static hudson.Util.createTempDir
/**
*
*
......@@ -22,6 +21,8 @@ class SecretRewriterTest {
@Rule
public ConfidentialStoreRule confidentialStoreRule = new ConfidentialStoreRule();
@Rule public TemporaryFolder tmp = new TemporaryFolder()
@Test
void singleFileRewrite() {
def o = encryptOld('foobar') // old
......@@ -48,14 +49,10 @@ class SecretRewriterTest {
void roundtrip(String before, String after) {
def sr = new SecretRewriter(null);
def f = File.createTempFile("test","xml");
try {
f.text = before
sr.rewrite(f,null)
assert after.trim()==f.text.trim()
} finally {
f.delete()
}
def f = File.createTempFile("test", "xml", tmp.root)
f.text = before
sr.rewrite(f,null)
assert after.trim()==f.text.trim()
}
String encryptOld(str) {
......@@ -73,7 +70,7 @@ class SecretRewriterTest {
*/
@Test
void recursionDetection() {
def backup = createTempDir()
def backup = tmp.newFolder("backup")
def sw = new SecretRewriter(backup);
def st = StreamTaskListener.fromStdout()
......@@ -83,7 +80,7 @@ class SecretRewriterTest {
def answer = "<msg>$n</msg>"
// set up some directories with stuff
def t = createTempDir()
def t = tmp.newFolder("t")
def dirs = ["a", "b", "c", "c/d", "c/d/e"]
dirs.each { p ->
def d = new File(t, p)
......@@ -92,7 +89,7 @@ class SecretRewriterTest {
}
// stuff outside
def t2 = createTempDir()
def t2 = tmp.newFolder("t2")
new File(t2,"foo.xml").text = payload
// some recursions as well as valid symlinks
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册