diff options
author | green <green@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-09-04 20:57:18 +0000 |
---|---|---|
committer | green <green@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-09-04 20:57:18 +0000 |
commit | ab52ed1d93305dfc203ec4ab2917c474a50ebc35 (patch) | |
tree | 3bd8341880b59044142121b372b25da9d563a293 /libjava | |
parent | 835f74c6b14c43a6eb61458c56ca14f7110ef1cf (diff) | |
download | gcc-ab52ed1d93305dfc203ec4ab2917c474a50ebc35.tar.gz |
Fix for PR java.io/203:
* java/io/File.java (createTempFile): Obey directory argument.
Use java.io.tmpdir if needed. Don't leave FileDescripators open.
* java/lang/natSystem.cc (init_properties): Use TMPDIR environment
variable to set java.io.tmpdir on non-WIN32 systems.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@36143 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava')
-rw-r--r-- | libjava/ChangeLog | 8 | ||||
-rw-r--r-- | libjava/java/io/File.java | 55 | ||||
-rw-r--r-- | libjava/java/lang/natSystem.cc | 6 |
3 files changed, 53 insertions, 16 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 6fd10ccfe5b..d4b4b94b8ad 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,5 +1,13 @@ 2000-09-04 Anthony Green <green@redhat.com> + Fix for PR java.io/203: + * java/io/File.java (createTempFile): Obey directory argument. + Use java.io.tmpdir if needed. Don't leave FileDescripators open. + * java/lang/natSystem.cc (init_properties): Use TMPDIR environment + variable to set java.io.tmpdir on non-WIN32 systems. + +2000-09-04 Anthony Green <green@redhat.com> + * java/io/File.java (deleteOnExit): New method. * gnu/gcj/runtime/FileDeleter.java: New class. * java/lang/natRuntime.cc (exit): Call diff --git a/libjava/java/io/File.java b/libjava/java/io/File.java index 9043660be38..01d8d53fee9 100644 --- a/libjava/java/io/File.java +++ b/libjava/java/io/File.java @@ -233,14 +233,26 @@ public class File implements Serializable File directory) throws IOException { - FileDescriptor desc = new FileDescriptor (); - - SecurityManager s = System.getSecurityManager(); - if (s != null) - s.checkWrite (desc); + // Grab the system temp directory if necessary + if (directory == null) + { + String dirname = tmpdir; + if (dirname == null) + throw + new IOException("Cannot determine system temporary directory"); + + directory = new File(dirname); + if (!directory.exists()) + throw new IOException("System temporary directory " + + directory.getName() + " does not exist."); + if (!directory.isDirectory()) + throw new IOException("System temporary directory " + + directory.getName() + + " is not really a directory."); + } if (prefix.length () < 3) - throw new IllegalArgumentException (); + throw new IllegalArgumentException ("Prefix too short: " + prefix); if (suffix == null) suffix = ".tmp"; @@ -259,8 +271,8 @@ public class File implements Serializable prefix = prefix.substring(0, max_length - 6 - suf_len); } - // We don't care about the name because we set it later. - File ret = new File (""); + File f; + // How many times should we try? We choose 100. for (int i = 0; i < 100; ++i) { @@ -269,18 +281,33 @@ public class File implements Serializable String l = prefix + t.substring(t.length() - 6) + suffix; try { - desc = new FileDescriptor - (l, FileDescriptor.WRITE | FileDescriptor.EXCL); - desc.close (); - ret.setPath(l); - return ret; + f = new File(directory, l); + if (f.exists()) + continue; + else + { + String af = f.getAbsolutePath (); + + // Check to see if we're allowed to write to it. + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkWrite (af); + + // Now create the file. + FileDescriptor fd = + new FileDescriptor (af, + FileDescriptor.WRITE + | FileDescriptor.EXCL); + fd.close (); + return f; + } } catch (IOException _) { } } - throw new IOException ("couldn't make temp file"); + throw new IOException ("cannot create temporary file"); } public static File createTempFile (String prefix, String suffix) diff --git a/libjava/java/lang/natSystem.cc b/libjava/java/lang/natSystem.cc index 2672895c6a4..39deab2ad04 100644 --- a/libjava/java/lang/natSystem.cc +++ b/libjava/java/lang/natSystem.cc @@ -244,8 +244,10 @@ java::lang::System::init_properties (void) SET ("file.separator", "/"); SET ("path.separator", ":"); SET ("line.separator", "\n"); - // FIXME: look at getenv("TMPDIR"); - SET ("java.io.tmpdir", "/tmp"); + char *tmpdir = ::getenv("TMPDIR"); + if (! tmpdir) + tmpdir = "/tmp"; + SET ("java.io.tmpdir", tmpdir); #endif #ifdef HAVE_UNAME |