Skip to content
Permalink
Browse files
[JENKINS-22088] Disk space leak with multiple copies of winstone-XXXX…
….jar in TEMP folder
  • Loading branch information
kuisathaverat committed Oct 4, 2017
1 parent a8f310f commit fe7acc205a251aa84dfb2bc50bccad1bc225426b
Showing with 27 additions and 0 deletions.
  1. +27 −0 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;
@@ -226,6 +227,8 @@ private static void _main(String[] args) throws Exception {
arguments.add("--webroot="+new File(describedHomeDir.file,"war"));
}

deleteWinstoneTempContents(extractedFilesFolder,"winstone.*\\.jar", "jna-.*");

// 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 +417,30 @@ private static File extractFromJar(String resource, String fileName, String suff
return tmp;
}

private static void deleteWinstoneTempContents(File folder, final String...patterns) throws IOException {
File tmpdir = folder;

if(tmpdir == null){
tmpdir = new File(System.getProperty("java.io.tmpdir"));
}

final File[] files = tmpdir.listFiles(new FilenameFilter() {
@Override
public boolean accept(final File dir, final String name) {
for (String pattern : patterns) {
if(name.matches(pattern)){
return true;
}
}
return false;
}
});
for (File file : files) {
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 fe7acc2

Please sign in to comment.