From 4b47cd42505eacfc85dab4f6d3969866ebef25c8 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Fri, 3 Feb 2017 11:02:42 -0500 Subject: [PATCH] =?UTF-8?q?[FIXED=20JENKINS-41068]=20When=20deleting=20a?= =?UTF-8?q?=20branch=20project,=20Job.delete=E2=80=99s=20call=20to=20getBu?= =?UTF-8?q?ildDir()=20was=20forcing=20MultiBranchProject.getRootDirFor=20t?= =?UTF-8?q?o=20recreate=20an=20empty=20job=20directory.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/jenkins/branch/MultiBranchProject.java | 13 ------------- .../jenkins/branch/WorkspaceLocatorImplTest.java | 6 +++++- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/main/java/jenkins/branch/MultiBranchProject.java b/src/main/java/jenkins/branch/MultiBranchProject.java index f244d03b..20357df4 100644 --- a/src/main/java/jenkins/branch/MultiBranchProject.java +++ b/src/main/java/jenkins/branch/MultiBranchProject.java @@ -756,19 +756,6 @@ public boolean hasPermission(Authentication a, Permission permission) { private static final Set SUPPRESSED_PERMISSIONS = ImmutableSet.of(Item.CONFIGURE, Item.DELETE, View.CONFIGURE, View.CREATE, View.DELETE); - /** - * {@inheritDoc} - */ - @Override - @NonNull - public File getRootDirFor(P child) { - File dir = super.getRootDirFor(child); - if (!dir.isDirectory() && !dir.mkdirs()) { // TODO is this really necessary? - LOGGER.log(Level.WARNING, "Could not create directory {0}", dir); - } - return dir; - } - /** * {@inheritDoc} */ diff --git a/src/test/java/jenkins/branch/WorkspaceLocatorImplTest.java b/src/test/java/jenkins/branch/WorkspaceLocatorImplTest.java index 20b4b945..bf4e8b57 100644 --- a/src/test/java/jenkins/branch/WorkspaceLocatorImplTest.java +++ b/src/test/java/jenkins/branch/WorkspaceLocatorImplTest.java @@ -28,6 +28,7 @@ import hudson.scm.NullSCM; import hudson.slaves.DumbSlave; import hudson.slaves.WorkspaceList; +import java.io.File; import java.util.Collections; import static jenkins.branch.NoTriggerBranchPropertyTest.showComputation; import jenkins.branch.harness.MultiBranchImpl; @@ -83,7 +84,7 @@ public void locate() throws Exception { assertEquals(r.jenkins.getRootPath().child("workspace/100% crazy"), r.jenkins.getWorkspaceFor(unrelated)); } - @Issue("JENKINS-2111") + @Issue({"JENKINS-2111", "JENKINS-41068"}) @Test public void delete() throws Exception { MultiBranchImpl p = r.createProject(MultiBranchImpl.class, "p"); @@ -111,6 +112,8 @@ public void delete() throws Exception { try (WorkspaceList.Lease lease = slave.toComputer().getWorkspaceList().acquire(slave.getWorkspaceFor(pr1))) { assertEquals(3, r.buildAndAssertSuccess(pr1).getNumber()); } + File pr1Root = pr1.getRootDir(); + assertTrue(pr1Root.isDirectory()); // Now delete PR-1 and make sure its workspaces are deleted too. p.getSourcesList().remove(pr1Source); p.scheduleBuild2(0).getFuture().get(); @@ -119,6 +122,7 @@ public void delete() throws Exception { assertEquals(Collections.singletonList(master), r.jenkins.getAllItems(FreeStyleProject.class)); assertEquals(Collections.singletonList(r.jenkins.getRootPath().child("workspace/p_master-NFABYX74Y6QHVCY2OKHXKUN4SSHQIWYYSJW7JE3FM65W5M5OSXMA")), r.jenkins.getRootPath().child("workspace").listDirectories()); assertEquals(Collections.singletonList(slave.getWorkspaceRoot().child("p_master-NFABYX74Y6QHVCY2OKHXKUN4SSHQIWYYSJW7JE3FM65W5M5OSXMA")), slave.getWorkspaceRoot().listDirectories()); + assertFalse(pr1Root.isDirectory()); } }