Skip to content

Commit

Permalink
Adding retries (5) to P4Server.clean (stuartr).
Browse files Browse the repository at this point in the history
JENKINS-26764
  • Loading branch information
p4paul committed Aug 18, 2016
1 parent 591e72d commit d7e62db
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/test/java/org/jenkinsci/plugins/p4/P4Server.java
Expand Up @@ -23,6 +23,7 @@
import org.jenkinsci.plugins.p4.credentials.P4PasswordImpl;

import com.cloudbees.plugins.credentials.CredentialsScope;
import java.util.logging.Level;

public class P4Server {

Expand Down Expand Up @@ -140,9 +141,25 @@ public void extract(File archive) throws Exception {
tarIn.close();
}

public void clean() throws IOException {
public void clean() throws IOException, InterruptedException {
if (p4root.exists()) {
FileUtils.cleanDirectory(p4root);
logger.log(Level.INFO, "Attempting to clean directory: {0}", p4root);
int retry = 0;
while (true) {
retry++;
try {
FileUtils.cleanDirectory(p4root);
break;
} catch (IOException e) {
if (retry < 5) {
logger.log(Level.WARNING, "Failed to clean directory, sleeping and retrying: {0}", e.getMessage());
Thread.sleep(1000);
} else {
logger.log(Level.SEVERE, "Failed to clean directory: {0}", e.getMessage());
throw e;
}
}
}
} else {
p4root.mkdir();
}
Expand Down

0 comments on commit d7e62db

Please sign in to comment.