classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [cp-patches] Re: FYI: java/io/FileInputStream.java& java/io/FileOutp


From: Jeroen Frijters
Subject: RE: [cp-patches] Re: FYI: java/io/FileInputStream.java& java/io/FileOutputStream.java
Date: Thu, 10 Mar 2005 09:13:19 +0100

Dalibor Topic wrote:
   /* Open a file.  MODE is a combination of the above mode flags. */
-  public FileChannelImpl (String path, int mode) throws
FileNotFoundException
+  public FileChannelImpl (File file, int mode) throws
FileNotFoundException
   {
+    final String path = file.getPath();
     fd = open (path, mode);
     this.mode = mode;
+
+    // First open the file and then check if it is a a directory
+    // to avoid race condition.
+    if (file.isDirectory())
+      throw new FileNotFoundException(file.getPath() + " is a
directory");
   }

I was actually thinking of something in the native code along the lines
of:

  int fd = open(...);
  stat m;
  fstat(fd, &m);
  if(IS_DIR(m))
  {
   close(fd);
   // throw FileNotFoundException
  }

But I now think that this might cause problems. When we're trying to
create a new file (new FileOutputStream()), O_TRUNC would be required,
but I have no idea what this does on a directory.

> OK, I'll post a patch that does that, without the close() part, after 
> some more testing and writing a muave test case. Thanks for your help!

What exactly do you mean by "the close() part"? The fact that the fd
should be closed in the constructor when the exception is thrown?

Regards,
Jeroen




reply via email to

[Prev in Thread] Current Thread [Next in Thread]