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
[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 fe7acc2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 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 Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit fe7acc2

Please sign in to comment.