Skip to content

Commit

Permalink
Merge pull request #78 from jglick/delete-branch-rootDir-JENKINS-41068
Browse files Browse the repository at this point in the history
[JENKINS-41068] When deleting a branch project, the root dir was recreated
  • Loading branch information
stephenc authored Feb 3, 2017
2 parents dd66d35 + 4b47cd4 commit d176a40
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
13 changes: 0 additions & 13 deletions src/main/java/jenkins/branch/MultiBranchProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -756,19 +756,6 @@ public boolean hasPermission(Authentication a, Permission permission) {
private static final Set<Permission> 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}
*/
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/jenkins/branch/WorkspaceLocatorImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand All @@ -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());
}

}

0 comments on commit d176a40

Please sign in to comment.