This is the mail archive of the
java-patches@sources.redhat.com
mailing list for the Java project.
Patch: java.io.File.deleteOnExit()
- To: java-patches at sources dot redhat dot com
- Subject: Patch: java.io.File.deleteOnExit()
- From: Anthony Green <green at cygnus dot com>
- Date: Mon, 4 Sep 2000 09:38:27 -0700
- Reply-to: green at cygnus dot com
Here's a patch I forgot to submit a few weeks ago. It adds support
for the deleteOnExit method to java.io.File. It also makes
performDelete static because there's no need for it not to be.
Ok to commit?
2000-09-04 Anthony Green <green@redhat.com>
* java/io/File.java (deleteOnExit): New method.
(performDelete): Make static.
* gnu/gcj/runtime/FileDeleter.java: New class.
* java/lang/natRuntime.cc (exit): Call
FileDeleter.deleteOnExitNow()
* Makefile.am: Add FileDeleter.java.
* Makefile.in: Rebuilt.
Index: Makefile.am
===================================================================
RCS file: /cvs/java/libgcj/libjava/Makefile.am,v
retrieving revision 1.85
diff -u -p -u -r1.85 Makefile.am
--- Makefile.am 2000/08/30 20:42:31 1.85
+++ Makefile.am 2000/09/04 16:32:56
@@ -733,6 +733,7 @@ gnu/gcj/protocol/http/Connection.java \
gnu/gcj/protocol/http/Handler.java \
gnu/gcj/protocol/jar/Connection.java \
gnu/gcj/protocol/jar/Handler.java \
+gnu/gcj/runtime/FileDeleter.java \
gnu/gcj/runtime/FirstThread.java \
gnu/gcj/runtime/VMClassLoader.java \
gnu/gcj/text/BaseBreakIterator.java \
Index: Makefile.in
===================================================================
RCS file: /cvs/java/libgcj/libjava/Makefile.in,v
retrieving revision 1.92
diff -u -p -u -r1.92 Makefile.in
--- Makefile.in 2000/08/30 20:43:48 1.92
+++ Makefile.in 2000/09/04 16:32:56
@@ -521,6 +521,7 @@ gnu/gcj/protocol/http/Connection.java \
gnu/gcj/protocol/http/Handler.java \
gnu/gcj/protocol/jar/Connection.java \
gnu/gcj/protocol/jar/Handler.java \
+gnu/gcj/runtime/FileDeleter.java \
gnu/gcj/runtime/FirstThread.java \
gnu/gcj/runtime/VMClassLoader.java \
gnu/gcj/text/BaseBreakIterator.java \
@@ -1084,7 +1085,7 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_D
.deps/gnu/gcj/protocol/http/Handler.P \
.deps/gnu/gcj/protocol/jar/Connection.P \
.deps/gnu/gcj/protocol/jar/Handler.P \
-.deps/gnu/gcj/runtime/FirstThread.P \
+.deps/gnu/gcj/runtime/FileDeleter.P .deps/gnu/gcj/runtime/FirstThread.P \
.deps/gnu/gcj/runtime/VMClassLoader.P \
.deps/gnu/gcj/text/BaseBreakIterator.P \
.deps/gnu/gcj/text/CharacterBreakIterator.P \
Index: java/io/File.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/io/File.java,v
retrieving revision 1.11
diff -u -p -u -r1.11 File.java
--- File.java 2000/07/20 19:29:14 1.11
+++ File.java 2000/09/04 16:32:56
@@ -10,6 +10,9 @@ details. */
package java.io;
+import java.util.*;
+import gnu.gcj.runtime.FileDeleter;
+
/**
* @author Tom Tromey <tromey@cygnus.com>
* @date September 24, 1998
@@ -42,7 +45,7 @@ public class File implements Serializabl
return access (p, WRITE);
}
- private final native boolean performDelete (String canon);
+ private final native static boolean performDelete (String canon);
public boolean delete ()
{
SecurityManager s = System.getSecurityManager();
@@ -345,6 +348,17 @@ public class File implements Serializabl
// Nothing.
}
return p;
+ }
+
+ // Add this File to the set of files to be deleted upon normal
+ // termination.
+ public void deleteOnExit ()
+ {
+ SecurityManager sm = System.getSecurityManager ();
+ if (sm != null)
+ sm.checkDelete (getName ());
+
+ FileDeleter.add (this);
}
// QUERY arguments to access function.
Index: java/lang/natRuntime.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natRuntime.cc,v
retrieving revision 1.12
diff -u -p -u -r1.12 natRuntime.cc
--- natRuntime.cc 2000/03/07 19:55:26 1.12
+++ natRuntime.cc 2000/09/04 16:32:56
@@ -17,6 +17,7 @@ details. */
#include <java/lang/Runtime.h>
#include <java/lang/UnknownError.h>
#include <java/lang/UnsatisfiedLinkError.h>
+#include <gnu/gcj/runtime/FileDeleter.h>
#include <jni.h>
@@ -84,6 +85,9 @@ java::lang::Runtime::exit (jint status)
if (finalize_on_exit)
_Jv_RunAllFinalizers ();
+
+ // Delete all files registered with File.deleteOnExit()
+ gnu::gcj::runtime::FileDeleter::deleteOnExitNow ();
::exit (status);
}
Index: gnu/gcj/runtime/FileDeleter.java
===================================================================
RCS file: FileDeleter.java
diff -N FileDeleter.java
--- /dev/null Tue May 5 13:32:27 1998
+++ FileDeleter.java Mon Sep 4 09:32:56 2000
@@ -0,0 +1,38 @@
+/* Copyright (C) 2000 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+package gnu.gcj.runtime;
+
+import java.io.*;
+import java.util.*;
+
+public final class FileDeleter
+{
+ public static void add (File f)
+ {
+ if (deleteOnExitStack == null)
+ deleteOnExitStack = new Stack ();
+
+ deleteOnExitStack.push (f);
+ }
+
+ // Helper method called by java.lang.Runtime.exit() to perform
+ // pending deletions.
+ public static void deleteOnExitNow ()
+ {
+ while (!deleteOnExitStack.empty ())
+ ((File)(deleteOnExitStack.pop ())).delete ();
+ }
+
+ // A stack of files to delete upon normal termination.
+ private static Stack deleteOnExitStack;
+}
+
+
+
+