RFR: 8356127: (fs) UnixFileSystemProvider.implDelete could save a syscall in some cases [v3]
Brian Burkhalter
bpb at openjdk.org
Fri May 9 22:32:50 UTC 2025
On Fri, 9 May 2025 17:01:09 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>>> It might be worth digging into how this works in NFS environments.
>>
>> I will try to assess this.
>
> I have a vague memory that NFSv4 had changes in this area to allow the REMOVE RPC handle any file type. Getting an up to date summary on that would be helpful as it may be that the change here will only work on local file systems.
A safer approach would be to remove the capability check and not to rely on the value of `errno` at all.
boolean isDirectory = false;
try {
try {
// assume the common case that the file is a regular file
unlink(file);
} catch (UnixException e) {
// check whether the file is a directory and, if so,
// try rmdir, otherwise re-throw and let the exception
// be handled below
isDirectory = UnixFileAttributes.get(file, false).isDirectory();
if (isDirectory) {
rmdir(file);
} else {
throw e;
}
}
return true;
} catch (UnixException x) {
// .... handle the exception ...
}
Of course this would be at the expense of a `stat` if the `unlink` fails, but that would at least be avoided for the common case of deleting a regular file.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25107#discussion_r2082574592
More information about the nio-dev
mailing list