diff options
author | Anthony Green <green@gcc.gnu.org> | 2000-09-04 16:55:48 +0000 |
---|---|---|
committer | Anthony Green <green@gcc.gnu.org> | 2000-09-04 16:55:48 +0000 |
commit | 890a31f478d6c419093c54b53111809540f4b9c4 (patch) | |
tree | 0e11c3202467de16f9293623c00841fbe6ad2149 | |
parent | 4993ddc14f3be5f5a4c858b16f237602262ba360 (diff) | |
download | gcc-890a31f478d6c419093c54b53111809540f4b9c4.zip gcc-890a31f478d6c419093c54b53111809540f4b9c4.tar.gz gcc-890a31f478d6c419093c54b53111809540f4b9c4.tar.bz2 |
File.java (deleteOnExit): New method.
* java/io/File.java (deleteOnExit): New method.
* gnu/gcj/runtime/FileDeleter.java: New class.
* java/lang/natRuntime.cc (exit): Call
FileDeleter.deleteOnExitNow()
* Makefile.am: Add FileDeleter.java.
* Makefile.in: Rebuilt.
From-SVN: r36141
-rw-r--r-- | libjava/Makefile.am | 1 | ||||
-rw-r--r-- | libjava/Makefile.in | 3 | ||||
-rw-r--r-- | libjava/gnu/gcj/runtime/FileDeleter.java | 38 | ||||
-rw-r--r-- | libjava/java/io/File.java | 16 | ||||
-rw-r--r-- | libjava/java/lang/natRuntime.cc | 4 |
5 files changed, 60 insertions, 2 deletions
diff --git a/libjava/Makefile.am b/libjava/Makefile.am index b296368..db05b63 100644 --- a/libjava/Makefile.am +++ b/libjava/Makefile.am @@ -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 \ diff --git a/libjava/Makefile.in b/libjava/Makefile.in index 5da8d91..84385b8 100644 --- a/libjava/Makefile.in +++ b/libjava/Makefile.in @@ -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_DIR)/gen-from-JIS.P \ .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 \ diff --git a/libjava/gnu/gcj/runtime/FileDeleter.java b/libjava/gnu/gcj/runtime/FileDeleter.java new file mode 100644 index 0000000..cc7aa9d --- /dev/null +++ b/libjava/gnu/gcj/runtime/FileDeleter.java @@ -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 synchronized 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; +} + + + + diff --git a/libjava/java/io/File.java b/libjava/java/io/File.java index b9ff9ff..9043660 100644 --- a/libjava/java/io/File.java +++ b/libjava/java/io/File.java @@ -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 Serializable 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(); @@ -347,6 +350,17 @@ public class File implements Serializable 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. private final static int READ = 0; private final static int WRITE = 1; diff --git a/libjava/java/lang/natRuntime.cc b/libjava/java/lang/natRuntime.cc index ad45066..9377165 100644 --- a/libjava/java/lang/natRuntime.cc +++ b/libjava/java/lang/natRuntime.cc @@ -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> @@ -85,6 +86,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); } |