Skip to content

Commit

Permalink
[FIXED JENKINS-18390] -P did not work with -Q; implementing prune man…
Browse files Browse the repository at this point in the history
…ually.
  • Loading branch information
jglick committed Jun 18, 2013
1 parent c4e376e commit 8499b09
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions src/main/java/hudson/scm/AbstractCvs.java
Expand Up @@ -27,6 +27,7 @@
import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
Expand Down Expand Up @@ -156,7 +157,7 @@ protected boolean checkout(CvsRepository[] repositories, boolean isFlatten, File
updateCommand.setUpdateByDate(dateStamp);
}

if (!perform(updateCommand, targetWorkspace, listener, repository, moduleName, envVars)) {
if (!perform(updateCommand, targetWorkspace, listener, repository, moduleName, envVars, pruneEmptyDirectories)) {
if (cleanOnFailedUpdate) {
updateFailed = true;
} else {
Expand Down Expand Up @@ -205,7 +206,7 @@ protected boolean checkout(CvsRepository[] repositories, boolean isFlatten, File
// and specify which module to load
checkoutCommand.setModule(envVars.expand(cvsModule.getRemoteName()));

if (!perform(checkoutCommand, targetWorkspace, listener, repository, moduleName, envVars)) {
if (!perform(checkoutCommand, targetWorkspace, listener, repository, moduleName, envVars, pruneEmptyDirectories)) {
return false;
}

Expand All @@ -232,7 +233,7 @@ protected boolean checkout(CvsRepository[] repositories, boolean isFlatten, File
* @throws InterruptedException if the user cancels the action
*/
private boolean perform(final Command cvsCommand, final FilePath workspace, final TaskListener listener,
final CvsRepository repository, final String moduleName, final EnvVars envVars)
final CvsRepository repository, final String moduleName, final EnvVars envVars, final boolean pruneEmptyDirectories)
throws IOException, InterruptedException {

final Client cvsClient = getCvsClient(repository, envVars, listener);
Expand All @@ -259,7 +260,18 @@ public Boolean invoke(final File workspace, final VirtualChannel channel) throws
cvsClient.getEventManager().addCVSListener(basicListener);

try {
return cvsClient.executeCommand(cvsCommand, globalOptions);
if (!cvsClient.executeCommand(cvsCommand, globalOptions)) {
return false;
}
if (pruneEmptyDirectories && !isDisableCvsQuiet()) {
try {
pruneEmptyDirectories(new File(workspace, moduleName));
} catch (IOException e) {
e.printStackTrace(listener.error("CVS empty directory cleanup failed: " + e.getMessage()));
return false;
}
}
return true;
} catch (CommandAbortedException e) {
e.printStackTrace(listener.error("CVS Command aborted: " + e.getMessage()));
return false;
Expand All @@ -285,6 +297,34 @@ public Boolean invoke(final File workspace, final VirtualChannel channel) throws
return true;
}

/**
* JENKINS-18390: work around buggy client.
* Cannot copy similarly-named method from {@link UpdateCommand} due to license mismatch.
* Cannot easily call the method reflectively on the {@link Command} since {@link CheckoutCommand} has a different signature for it.
* Pending a fix in the client library, do it ourselves when necessary.
*/
private static void pruneEmptyDirectories(File d) throws IOException {
File[] kids = d.listFiles();
if (kids == null) {
throw new IOException("could not examine " + d);
}
for (File kid : kids) {
if (!kid.isDirectory()) {
continue;
}
if (!new File(kid, "CVS").isDirectory()) {
// not CVS-controlled, ignore
continue;
}
pruneEmptyDirectories(kid);
File[] subkids = kid.listFiles();
if (subkids != null && subkids.length == 1) {
// Just CVS.
Util.deleteRecursive(kid);
}
}
}

/**
* Gets an instance of the CVS client that can be used for connection to a repository. If the
* repository specifies a password then the client's connection will be set with this password.
Expand Down

0 comments on commit 8499b09

Please sign in to comment.