[kaffe] CVS kaffe (dalibor): Resynced with GNU Classpath: deleting files on exit

Kaffe CVS cvs-commits at kaffe.org
Thu May 20 12:47:14 PDT 2004


PatchSet 4756 
Date: 2004/05/20 18:13:47
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: deleting files on exit

2004-05-20  Dalibor Topic  <robilad at kaffe.org>

        * libraries/javalib/java/io/DeleteFileHelper.java:
        New file, taken from GNU Classpath.

        * libraries/javalib/java/io/File.java:
        Resynced with GNU Classpath.

        * libraries/javalib/Makefile.am,
        libraries/javalib/Makefile.in:
        Regenerated.

        * libraries/javalib/essential.files:
        Added java/io/DeleteFileHelper.java.

        2004-05-19  Guilhem Lavaux  <guilhem at kaffe.org>

        * java/io/DeleteFileHelper.java: New file.
        * java/io/File.java
        (deleteOnExit): Implemented.

Members: 
	ChangeLog:1.2327->1.2328 
	libraries/javalib/Makefile.am:1.189->1.190 
	libraries/javalib/Makefile.in:1.252->1.253 
	libraries/javalib/essential.files:1.44->1.45 
	libraries/javalib/java/io/DeleteFileHelper.java:INITIAL->1.1 
	libraries/javalib/java/io/File.java:1.46->1.47 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2327 kaffe/ChangeLog:1.2328
--- kaffe/ChangeLog:1.2327	Thu May 20 13:51:38 2004
+++ kaffe/ChangeLog	Thu May 20 18:13:47 2004
@@ -1,5 +1,26 @@
 2004-05-20  Dalibor Topic  <robilad at kaffe.org>
 
+	* libraries/javalib/java/io/DeleteFileHelper.java:
+	New file, taken from GNU Classpath.
+
+	* libraries/javalib/java/io/File.java:
+	Resynced with GNU Classpath.
+
+        * libraries/javalib/Makefile.am,
+        libraries/javalib/Makefile.in:
+	Regenerated.
+
+        * libraries/javalib/essential.files:
+	Added java/io/DeleteFileHelper.java.
+
+	2004-05-19  Guilhem Lavaux  <guilhem at kaffe.org>
+
+        * java/io/DeleteFileHelper.java: New file.
+        * java/io/File.java
+        (deleteOnExit): Implemented.
+
+2004-05-20  Dalibor Topic  <robilad at kaffe.org>
+
 	* kaffe/kaffe/main.c:
 	(options) Added -Xbootclasspath and Xbootclasspath/a
 	option handling.
Index: kaffe/libraries/javalib/Makefile.am
diff -u kaffe/libraries/javalib/Makefile.am:1.189 kaffe/libraries/javalib/Makefile.am:1.190
--- kaffe/libraries/javalib/Makefile.am:1.189	Wed May 19 17:27:53 2004
+++ kaffe/libraries/javalib/Makefile.am	Thu May 20 18:13:50 2004
@@ -1090,6 +1090,7 @@
 	java/io/DataInputStream.java \
 	java/io/DataOutput.java \
 	java/io/DataOutputStream.java \
+	java/io/DeleteFileHelper.java \
 	java/io/EOFException.java \
 	java/io/Externalizable.java \
 	java/io/FileDescriptor.java \
Index: kaffe/libraries/javalib/Makefile.in
diff -u kaffe/libraries/javalib/Makefile.in:1.252 kaffe/libraries/javalib/Makefile.in:1.253
--- kaffe/libraries/javalib/Makefile.in:1.252	Wed May 19 17:27:54 2004
+++ kaffe/libraries/javalib/Makefile.in	Thu May 20 18:13:51 2004
@@ -1443,6 +1443,7 @@
 	java/io/DataInputStream.java \
 	java/io/DataOutput.java \
 	java/io/DataOutputStream.java \
+	java/io/DeleteFileHelper.java \
 	java/io/EOFException.java \
 	java/io/Externalizable.java \
 	java/io/FileDescriptor.java \
Index: kaffe/libraries/javalib/essential.files
diff -u kaffe/libraries/javalib/essential.files:1.44 kaffe/libraries/javalib/essential.files:1.45
--- kaffe/libraries/javalib/essential.files:1.44	Tue May 18 03:35:02 2004
+++ kaffe/libraries/javalib/essential.files	Thu May 20 18:13:51 2004
@@ -84,6 +84,7 @@
 java/io/DataOutputStream.java
 java/io/EOFException.java
 java/io/Externalizable.java
+java/io/DeleteFileHelper.java
 java/io/File.java
 java/io/FileDescriptor.java
 java/io/FileFilter.java
===================================================================
Checking out kaffe/libraries/javalib/java/io/DeleteFileHelper.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/java/io/DeleteFileHelper.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/java/io/DeleteFileHelper.java	Thu May 20 18:19:29 2004
@@ -0,0 +1,112 @@
+/* DeleteFileHelper.java -- Helper class to delete files on VM exit
+   Copyright (C) 2004  Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+ 
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.io;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * @author Guilhem Lavaux (guilhem at kaffe.org)
+ * @author Jeroen Frijters (jeroen at sumatra.nl)
+ * @author Michael Koch (konqueror at gmx.de)
+ */
+public final class DeleteFileHelper extends Thread
+{
+  private static ArrayList filesToDelete;
+
+  static
+  {
+    Runtime.getRuntime().addShutdownHook(new DeleteFileHelper());
+  }
+
+  static synchronized void add(File file)
+  {
+    if (filesToDelete == null)
+      {
+        filesToDelete = new ArrayList();
+        
+        AccessController.doPrivileged(new PrivilegedAction()
+          {
+            public Object run()
+            {
+              try
+                {
+                  Runtime.getRuntime().addShutdownHook(new DeleteFileHelper());
+                }
+              catch (IllegalStateException e)
+                {
+                  // Shutdown is already in progress, so we can't register ours.
+                }
+                
+              return null;
+            }
+          });
+      }
+      
+    filesToDelete.add(file);
+  }
+
+  private static synchronized void deleteFiles()
+  {
+    Iterator it = filesToDelete.iterator();
+	
+    while (it.hasNext())
+      {
+	try
+	  {
+	    File file = (File) it.next();
+	    file.delete();
+	  }
+	catch (Exception e)
+	  {
+	    // Do nothing here.
+	  }
+      }
+  }
+
+  private DeleteFileHelper()
+  {
+  }
+  
+  public void run()
+  {
+    deleteFiles();
+  }
+}
Index: kaffe/libraries/javalib/java/io/File.java
diff -u kaffe/libraries/javalib/java/io/File.java:1.46 kaffe/libraries/javalib/java/io/File.java:1.47
--- kaffe/libraries/javalib/java/io/File.java:1.46	Tue May 18 03:35:03 2004
+++ kaffe/libraries/javalib/java/io/File.java	Thu May 20 18:13:52 2004
@@ -45,8 +45,6 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.util.Iterator;
-import java.util.LinkedList;
 
 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
  * "The Java Language Specification", ISBN 0-201-63451-1
@@ -1184,37 +1182,6 @@
       s.checkRead(path);
   }
 
-  static class DeleteFileHelper extends Thread
-  {
-    LinkedList filesToDelete = new LinkedList();
-
-    public DeleteFileHelper()
-    {
-      Runtime.getRuntime().addShutdownHook (this);
-    }
-    
-    public void run()
-    {
-      Iterator fileIterator = filesToDelete.iterator();
-
-      while (fileIterator.hasNext())
-	{
-	  String path = (String)fileIterator.next();
-	  try
-	    {
-	      File f = new File(path);
-
-	      f.delete();
-	    }
-	  catch (Throwable _)
-	    {
-	    }
-	}
-    }
-  }
-
-  private static DeleteFileHelper deleteHelper = new DeleteFileHelper();
-
   /** 
    * Calling this method requests that the file represented by this object
    * be deleted when the virtual machine exits.  Note that this request cannot
@@ -1232,7 +1199,7 @@
     if (sm != null)
       sm.checkDelete(path);
 
-    deleteHelper.filesToDelete.add(getAbsolutePath());
+    DeleteFileHelper.add(this);
   }
 
   private void writeObject(ObjectOutputStream oos) throws IOException




More information about the kaffe mailing list