Deleting symbolic links via the java.nio.file.Path API
fm
fudmail at gmail.com
Mon Oct 11 08:07:33 PDT 2010
Sorry. I was being careless when I threw the checkAccess method into
my conversation...I didn't think that one through. You are right,
checkAccess does not seem to make sense for the symbolic links
themselves (as opposed to their targets).
However, I believe my concern with respect to checking the existence
of symbolic links with the exists method is still reasonable.
Just to provide another example. The following code throws a
FileAlreadyExistsException when somePath corresponds to a broken
symbolic link.
try {
if (!somePath.exists()) // or use somePath.notExists()
somePath.createFile();
}
catch (FileAlreadyExistsException e) {
System.err.println("File exists!?!");
}
catch (IOException e) { }
Being able to call something like
"somePath.exists(LinkOption.NOFOLLOW_LINKS)" would be helpful.
On Sat, Oct 9, 2010 at 11:51 AM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> fm wrote:
>>
>> :
>>
>> My 2 cents is that the exists, notExists, and checkAccess methods
>> should have the following signatures:
>>
>> void checkAccess(AccessMode[] modes, LinkOption... options)
>>
>> boolean exists(LinkOption... options)
>>
>> boolean notExists(LinkOption... options)
>>
>> This would add convenience by enabling the programmer to avoid
>> accessing file attributes (and handling an IOException) just to
>> determine if something exists on the file system that corresponds to a
>> java.nio.file.Path instance.
>>
>
> There may be a case where you want to check if a file exists without
> following links, but I'm not sure that it really make sense for checkAccess.
> What does it mean for a sym link to be writable or executable for example.
> In the native world, there isn't an laccess so it's not something that
> native code can readily do either (it can simulate it but there may be
> subtle differences).
>
> One thing I should say is that checkAccess does need to be re-examined (we
> have a bug tracking this) so I'll add it to the list of things to look at
> (for the exists case anyway).
>
> -Alan
>
More information about the nio-dev
mailing list