Skip to content
This repository has been archived by the owner on Sep 8, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #12 from kuisathaverat/JENKINS-22088
[JENKINS-22088] Disk space leak
  • Loading branch information
oleg-nenashev committed Jan 9, 2018
2 parents a8f310f + 8f00f05 commit 3aa664c
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/main/java/Main.java
Expand Up @@ -27,6 +27,7 @@
import javax.naming.Context;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -39,7 +40,6 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
Expand Down Expand Up @@ -226,6 +226,11 @@ private static void _main(String[] args) throws Exception {
arguments.add("--webroot="+new File(describedHomeDir.file,"war"));
}

//only do a cleanup if you set the extractedFilesFolder property.
if(extractedFilesFolder != null) {
deleteContentsFromFolder(extractedFilesFolder, "winstone.*\\.jar");
}

// put winstone jar in a file system so that we can load jars from there
File tmpJar = extractFromJar("winstone.jar","winstone",".jar", extractedFilesFolder);
tmpJar.deleteOnExit();
Expand Down Expand Up @@ -414,6 +419,27 @@ private static File extractFromJar(String resource, String fileName, String suff
return tmp;
}

/**
* Search contents to delete in a folder that match with some patterns.
* @param folder folder where the contents are.
* @param patterns patterns that identifies the contents to search.
* @throws IOException in case of error deleting contents.
*/
private static void deleteContentsFromFolder(File folder, final String...patterns) throws IOException {
File[] files = folder.listFiles();

if(files != null){
for (File file : files) {
for (String pattern : patterns) {
if(file.getName().matches(pattern)){
LOGGER.log(Level.FINE, "Deleting the temporary file {0}", file);
deleteWinstoneTempContents(file);
}
}
}
}
}

private static void deleteWinstoneTempContents(File file) throws IOException {
if(file.isDirectory()) {
File[] files = file.listFiles();
Expand Down

0 comments on commit 3aa664c

Please sign in to comment.