File.isFile() and links

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

File.isFile() and links

Daniel Naber
Hi,

I'd like to add this code to FSDirectory.create():

    if (directory.isFile())
      throw new IOException("Expected directory, but '" + directory + "' is
          a file");

This way people will get a useful exception if they specify a file instead
of a directory (currently this leads to a NPE). Of course it should still
be possible to specify a link that points to a directory. I tried it here
(Suse Linux 9.1) and it works. But will it work on other systems? The
Javadoc of the File class doesn't say whether a link is a file or not.

Regards
 Daniel

--
http://www.danielnaber.de

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: File.isFile() and links

Otis Gospodnetic-2
On Fedora Core 3 this returns false when you use it to test a symlink
that points to a directory.  I think the same will be true on all
UNIX-like operating system.  I think Windows and its shortcuts is the
question, and I don't have a Windows machine handy to test.

Otis


--- Daniel Naber <[hidden email]> wrote:

> Hi,
>
> I'd like to add this code to FSDirectory.create():
>
>     if (directory.isFile())
>       throw new IOException("Expected directory, but '" + directory +
> "' is
>           a file");
>
> This way people will get a useful exception if they specify a file
> instead
> of a directory (currently this leads to a NPE). Of course it should
> still
> be possible to specify a link that points to a directory. I tried it
> here
> (Suse Linux 9.1) and it works. But will it work on other systems? The
>
> Javadoc of the File class doesn't say whether a link is a file or
> not.
>
> Regards
>  Daniel
>
> --
> http://www.danielnaber.de
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: File.isFile() and links

Daniel Naber
On Sunday 08 May 2005 04:39, Otis Gospodnetic wrote:

> On Fedora Core 3 this returns false when you use it to test a symlink
> that points to a directory.

It turns out !d.isDirectory() is already used in a different place, so we
can assume it's okay, as nobody ever complained about it I think.

Regards
 Daniel

--
http://www.danielnaber.de

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]