geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1088178 - /geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java
Date Sat, 02 Apr 2011 23:29:00 GMT
Author: dblevins
Date: Sat Apr  2 23:29:00 2011
New Revision: 1088178

URL: http://svn.apache.org/viewvc?rev=1088178&view=rev
Log:
GERONIMO-5888: Delete temp directories on exit

Modified:
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java?rev=1088178&r1=1088177&r2=1088178&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java
Sat Apr  2 23:29:00 2011
@@ -30,6 +30,7 @@ import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -37,6 +38,7 @@ import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.jar.JarFile;
@@ -81,6 +83,7 @@ public class FileUtils {
         File tempDir = File.createTempFile("geronimo-fileutils", ".tmpdir");
         tempDir.delete();
         tempDir.mkdirs();
+        deleteOnExit(tempDir);
         return tempDir;
     }
 
@@ -409,4 +412,37 @@ public class FileUtils {
 
     private FileUtils() {
     }
+
+    // Shutdown hook for recurssive delete on tmp directories
+    static final List<String> delete = new ArrayList<String>();
+
+    static {
+        Runtime.getRuntime().addShutdownHook(new Thread(){
+            @Override
+            public void run() {
+                delete();
+            }
+        });
+    }
+
+    private static void deleteOnExit(File file) {
+        delete.add(file.getAbsolutePath());
+    }
+
+    private static void delete() {
+        for (String path : delete) {
+            delete(new File(path));
+        }
+    }
+
+    private static void delete(File file) {
+        if (file.isDirectory()) {
+            for (File f : file.listFiles()) {
+                delete(f);
+            }
+        }
+
+        file.delete();
+    }
+
 }



Mime
View raw message