You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The default file system provider returns URI's with trailing slashes if the URI is known to refer to a directory. This only way to know for sure if a URI refers to a directory or a file is if the directory actually exists on disk. For example:
Hmm... curious. I'm surprised (assuming this is what it does) that the default file system would take the time to stat a file when creating a URI for it. I would expect the URI for a path to be independent of the file's actual status on the file system (as most things on Path are, with the exception of toRealPath() primarily), particularly given that the status can change at any time.
…ile is a directory.
See this issue: #16
I was initially reluctant to do this because it seems strange to actually access the file system to convert a path to a URI, but this does in fact seem to be the behavior for actual Unix paths. Additionally, when looking into creating a ClassLoader that takes Path objects for the classpath, I noticed that URLClassLoader treats URLs that end with / differently (as directories) from those that don't, which indicates that there are real consequences for not doing this. Note: URLClassLoader is tied to the default file system via File/JarFile by default, so it's not like this change actually enables it to just work with Jimfs files (nor do I have any real reason to think you'd even want to do that, I was just curious).
This involves changing the PathType API to take a boolean parameter indicating whether or not the file is a directory in its method for getting a URI path, which makes this an incompatible change that would probably require a 2.0 release (not that I expect anyone's actually implementing their own PathType).
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=87278575
The default file system provider returns URI's with trailing slashes if the URI is known to refer to a directory. This only way to know for sure if a URI refers to a directory or a file is if the directory actually exists on disk. For example:
If C:\dir1\ does not exist before running this code, the result will be:
file:///C:/
file:///C:/dir1
file:///C:/dir1/
file:///C:/dir1/
Notice that dir1.toUri() does not contain a trailing slash before the directory is created, but it does contain a trailing slash afterward.
I have verified this same behavior on OSX as well.
The text was updated successfully, but these errors were encountered: