RFR: 8295753: (fs) UnixPath::toRealPath does not return correct case when links not followed [v2]

Alan Bateman alanb at openjdk.org
Tue Nov 1 07:51:20 UTC 2022


On Tue, 25 Oct 2022 23:36:27 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> On macOS, ensure that the components of the `Path` returned by `UnixPath::toRealPath` have the case retained by the file system as opposed to that of the representation present in the `UnixPath` instance.
>
> Brian Burkhalter has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:
> 
>  - Merge
>  - 8295753: Use UnixDirectoryStream; compare UnixFileKeys; add SecurityManager
>  - 8295753: (fs) UnixPath::toRealPath does not return correct case when links not followed

src/java.base/unix/classes/sun/nio/fs/UnixPath.java line 871:

> 869: 
> 870:         // Return if the file system is not both case insensitive and retentive
> 871:         if (!fs.isCaseInsensitiveAndRetentive())

I think we need to find a better name for this method. Maybe "Preserving" rather than "Retentive" would work better here.

src/java.base/unix/classes/sun/nio/fs/UnixPath.java line 882:

> 880:         // entry in the same directory which has an equal key
> 881:         for (int i = 0; i < result.getNameCount(); i++ ) {
> 882:             UnixPath elt = result.getName(i);

Minor nit but the the naming above is "element", it switches to "elt" here.

src/java.base/unix/classes/sun/nio/fs/UnixPath.java line 906:

> 904:             // Check readbility of path thus far
> 905:             if (sm != null)
> 906:                 sm.checkRead(path.getPathForPermissionCheck());

I don't think this permission check is needed here. The "checkRead" at line 816 does the require check for the method.

src/java.base/unix/classes/sun/nio/fs/UnixPath.java line 914:

> 912:                     attributes = UnixFileAttributes.get(toUnixPath(p), false);
> 913:                 } catch (UnixException x) {
> 914:                     x.rethrowAsIOException(this);

This is problematic as it means that toRealPath can fail trying to access a file that is not in the path. Also given that it is only looking for one file then it might be simpler to just handle in the loop rather than as a filter.

-------------

PR: https://git.openjdk.org/jdk/pull/10843


More information about the nio-dev mailing list