Skip to content
Permalink
Browse files
[FIXED JENKINS-26250] Asynchronous delete of workspace does not detec…
…t fail to rename
  • Loading branch information
olivergondza committed Jan 26, 2015
1 parent 478158f commit ab81960e0d39b339f12e034eaf704269161a222d
Showing 2 changed files with 36 additions and 1 deletion.
@@ -25,6 +25,8 @@

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import hudson.FilePath;
import hudson.FilePath.FileCallable;
@@ -51,6 +53,16 @@
protected void perform(FilePath workspace) throws IOException, InterruptedException {
final FilePath deleteMe = workspace.withSuffix("_ws-cleanup_" + System.currentTimeMillis());
workspace.renameTo(deleteMe);

if (!deleteMe.exists()) {
LOGGER.log(
Level.WARNING,
"Cleaning workspace synchronously. Failed to rename {0} to {1}.",
new Object[] { workspace.getRemote(), deleteMe.getName() }
);
workspace.act(COMMAND);
}

deleteMe.actAsync(COMMAND);
}

@@ -61,4 +73,6 @@ public Object invoke(File f, VirtualChannel channel) throws IOException, Interru
return null;
}
}

private static final Logger LOGGER = Logger.getLogger(Wipeout.class.getName());
}
@@ -25,7 +25,9 @@

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import hudson.FilePath;
import hudson.Functions;
import hudson.Launcher;
import hudson.matrix.AxisList;
import hudson.matrix.MatrixRun;
@@ -51,6 +53,7 @@

import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.JenkinsRule;

public class CleanupTest {
@@ -150,6 +153,24 @@ public void deleteWorkspaceWithNonAsciiCharacters() throws Exception {
assertWorkspaceCleanedUp(build);
}

@Test @Bug(26250)
public void doNotFailToWipeoutWhenRenameFails() throws Exception {
assumeTrue(!Functions.isWindows()); // chmod does not work here

FreeStyleProject p = j.jenkins.createProject(FreeStyleProject.class, "sut");
populateWorkspace(p, "content.txt");
p.getPublishersList().add(wipeoutPublisher());

FilePath workspace = p.getLastBuild().getWorkspace();
workspace.getParent().chmod(0555); // Remove write for parent dir so rename will fail

workspace.renameTo(workspace.withSuffix("2"));
assertTrue("Rename operation should fail", workspace.exists());

FreeStyleBuild build = j.buildAndAssertSuccess(p);
assertWorkspaceCleanedUp(build);
}

private WsCleanup wipeoutPublisher() {
return new WsCleanup(Collections.<Pattern>emptyList(), false,
true, true, true, true, true, true, true, // run always
@@ -163,7 +184,7 @@ private void populateWorkspace(FreeStyleProject p, String filename) throws Excep
assertFalse("Workspace populated", b.getWorkspace().list().isEmpty());
}

private void assertWorkspaceCleanedUp(AbstractBuild b) throws Exception {
private void assertWorkspaceCleanedUp(AbstractBuild<?, ?> b) throws Exception {
final FilePath workspace = b.getWorkspace();
if (workspace == null) return; // removed

0 comments on commit ab81960

Please sign in to comment.