geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1171698 - /geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java
Date Fri, 16 Sep 2011 18:05:59 GMT
Author: dblevins
Date: Fri Sep 16 18:05:58 2011
New Revision: 1171698

URL: http://svn.apache.org/viewvc?rev=1171698&view=rev
Log:
Re-adding https://issues.apache.org/jira/browse/GERONIMO-5888

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=1171698&r1=1171697&r2=1171698&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
Fri Sep 16 18:05:58 2011
@@ -29,6 +29,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;
@@ -111,6 +112,7 @@ public class FileUtils {
         File tempDir = File.createTempFile(DEFAULT_TEMP_PREFIX, DEFAULT_TEMP_DIRECTORY_SUFFIX);
         tempDir.delete();
         tempDir.mkdirs();
+        deleteOnExit(tempDir);
         addTempFile(tempDir);
         return tempDir;
     }
@@ -448,4 +450,37 @@ public class FileUtils {
 
     private FileUtils() {
     }
+
+    static final List<String> delete = new ArrayList<String>();
+
+    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();
+    }
+
+     // Shutdown hook for recurssive delete on tmp directories
+
+    static {
+        Runtime.getRuntime().addShutdownHook(new Thread(){
+            @Override
+            public void run() {
+                delete();
+            }
+        });
+    }
 }



Mime
View raw message