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
This commit is contained in:
parent
4993ddc14f
commit
890a31f478
@ -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 \
|
||||
|
@ -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 \
|
||||
|
38
libjava/gnu/gcj/runtime/FileDeleter.java
Normal file
38
libjava/gnu/gcj/runtime/FileDeleter.java
Normal file
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user