Skip to content
Permalink
Browse files
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 3aa664c3880534e98aac9dd496cf67afeeef1f16
Showing with 27 additions and 1 deletion.
  1. +27 −1 src/main/java/Main.java
@@ -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;
@@ -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;
@@ -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();
@@ -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();

0 comments on commit 3aa664c

Please sign in to comment.