From c49d6b5b3b58282a37deb5fb88bcf44a3f5bbfc0 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 20 Mar 2013 11:23:01 -0400 Subject: [PATCH] =?UTF-8?q?Use=20TemporaryFolder=20to=20good=20effect.=20P?= =?UTF-8?q?revents=20us=20from=20leaving=20behind=20a=20temp=20dir=20with?= =?UTF-8?q?=20cyclic=20symlinks,=20which=20breaks=20JGit=E2=80=99s=20clean?= =?UTF-8?q?=20function.=20That=20in=20turn=20can=20cause=20test=20builds?= =?UTF-8?q?=20to=20break:=20https://jenkins.ci.cloudbees.com/job/core/job/?= =?UTF-8?q?jenkins=5Fmain=5Ftrunk/783/console=20Cleaning=20workspace=20FAT?= =?UTF-8?q?AL:=20Could=20not=20delete=20file=20=E2=80=A6/workspace/core/je?= =?UTF-8?q?nkins=5Fmain=5Ftrunk/core/target/hudson5309354136960541268tmp/c?= =?UTF-8?q?/symlink/c/symlink/c/symlink/=E2=80=A6/c/foo.xml=20org.eclipse.?= =?UTF-8?q?jgit.api.errors.JGitInternalException:=20Could=20not=20delete?= =?UTF-8?q?=20file=20=E2=80=A6/workspace/core/jenkins=5Fmain=5Ftrunk/core/?= =?UTF-8?q?target/hudson5309354136960541268tmp/c/symlink/c/symlink/c/symli?= =?UTF-8?q?nk/=E2=80=A6/c/foo.xml=20=09at=20org.eclipse.jgit.api.CleanComm?= =?UTF-8?q?and.call(CleanCommand.java:137)=20=09at=20org.jenkinsci.plugins?= =?UTF-8?q?.gitclient.JGitAPIImpl.clean(JGitAPIImpl.java:305)=20=09at=20hu?= =?UTF-8?q?dson.plugins.git.GitAPI.clean(GitAPI.java:248)=20=09at=20hudson?= =?UTF-8?q?.plugins.git.GitSCM$4.invoke(GitSCM.java:1213)=20=09at=20hudson?= =?UTF-8?q?.plugins.git.GitSCM$4.invoke(GitSCM.java:1196)=20=09at=20hudson?= =?UTF-8?q?.FilePath$FileCallableWrapper.call(FilePath.java:2236)=20=09at?= =?UTF-8?q?=20hudson.remoting.UserRequest.perform(UserRequest.java:118)=20?= =?UTF-8?q?=09at=20hudson.remoting.UserRequest.perform(UserRequest.java:48?= =?UTF-8?q?)=20=09at=20hudson.remoting.Request$2.run(Request.java:326)=20?= =?UTF-8?q?=09at=20hudson.remoting.InterceptingExecutorService$1.call(Inte?= =?UTF-8?q?rceptingExecutorService.java:72)=20=09at=20java.util.concurrent?= =?UTF-8?q?.FutureTask$Sync.innerRun(FutureTask.java:334)=20=09at=20java.u?= =?UTF-8?q?til.concurrent.FutureTask.run(FutureTask.java:166)=20=09at=20ja?= =?UTF-8?q?va.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecu?= =?UTF-8?q?tor.java:1145)=20=09at=20java.util.concurrent.ThreadPoolExecuto?= =?UTF-8?q?r$Worker.run(ThreadPoolExecutor.java:615)=20=09at=20java.lang.T?= =?UTF-8?q?hread.run(Thread.java:722)=20Caused=20by:=20java.io.IOException?= =?UTF-8?q?:=20Could=20not=20delete=20file=20=E2=80=A6/workspace/core/jenk?= =?UTF-8?q?ins=5Fmain=5Ftrunk/core/target/hudson5309354136960541268tmp/c/s?= =?UTF-8?q?ymlink/c/symlink/c/symlink/=E2=80=A6/c/foo.xml=20=09at=20org.ec?= =?UTF-8?q?lipse.jgit.util.FileUtils.delete(FileUtils.java:142)=20=09at=20?= =?UTF-8?q?org.eclipse.jgit.util.FileUtils.delete(FileUtils.java:126)=20?= =?UTF-8?q?=09at=20org.eclipse.jgit.util.FileUtils.delete(FileUtils.java:1?= =?UTF-8?q?26)=20=09=E2=80=A6=20=09at=20org.eclipse.jgit.util.FileUtils.de?= =?UTF-8?q?lete(FileUtils.java:126)=20=09at=20org.eclipse.jgit.util.FileUt?= =?UTF-8?q?ils.delete(FileUtils.java:126)=20=09at=20org.eclipse.jgit.api.C?= =?UTF-8?q?leanCommand.call(CleanCommand.java:132)=20=09...=2014=20more?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hudson/util/SecretRewriterTest.groovy | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/core/src/test/java/hudson/util/SecretRewriterTest.groovy b/core/src/test/java/hudson/util/SecretRewriterTest.groovy index 13522c22ad..d732dcb716 100644 --- a/core/src/test/java/hudson/util/SecretRewriterTest.groovy +++ b/core/src/test/java/hudson/util/SecretRewriterTest.groovy @@ -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 = "$n" // 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 -- GitLab