New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve IO.toFile for Windows (URI has an authority component) #3088
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eed3si9n
changed the title
Improve IO.toFile's for Windows
Improve IO.toFile for Windows
Apr 8, 2017
Improve IO.toFile's handling for Windows, and use it for identifying resolvers. This adds support to convert URL to File on Windows in several ways: ``` val u0 = new URL("file:C:\\Users\\foo/.sbt/preloaded") val u1 = new URL("file:/C:\\Users\\foo/.sbt/preloaded") val u2 = new URL("file://unc/Users/foo/.sbt/preloaded") val u3 = new URL("file:///C:\\Users\\foo/.sbt/preloaded") val u4 = new URL("file:////unc/Users/foo/.sbt/preloaded") ``` Note that `u0` and `u2` are something `new File(u.toURI)` won't handle. This also correctly handles UNC convention specified by Microsoft in https://blogs.msdn.microsoft.com/ie/2006/12/06/file-uris-in-windows/. Fixes sbt#3086 Fixes sbt#2150
On Mac and Linux, user.home should return `/home/foo`, resulting to `file:/home/foo`. On Windows, user.home should return `C:\Users\foo`, resulting to `file:C:/Users/foo`.
eed3si9n
force-pushed
the
wip/windows_file
branch
from
April 8, 2017 08:00
d36a12d
to
de3d711
Compare
dwijnand
approved these changes
Apr 8, 2017
I hit this so much, I solved it in class-monkey, you should have asked :-P |
eed3si9n
changed the title
Improve IO.toFile for Windows
Improve IO.toFile for Windows (URI has an authority component)
Apr 8, 2017
eed3si9n
added a commit
to eed3si9n/sbt
that referenced
this pull request
Apr 9, 2017
sbt#3088 attemped to fix the sbt#3086, but by putting no slashes in `sbt.boot.properties` the launcher created by 0.13.15-* becomes incompatible for all previous sbt versions. The uglier but backward compatible fix for sbt#3086 is to use u3 format with three slashes. This on Windows will resolve to `file:///C:/Users/foo/.sbt/preloaded`, and on Mac and Linux `file:////root/.sbt/preloaded/`. Mac and Linux are both tolerant of extra slashes on the front: ``` > eval new File(new URL("file:////Users/foo/.sbt/preloaded/").toURI) [info] ans: java.io.File = /Users/foo/.sbt/preloaded ```
This was referenced Apr 9, 2017
eed3si9n
added a commit
to eed3si9n/sbt
that referenced
this pull request
Sep 25, 2017
Node didn't seem to like read URI out of the box, and I am not sure if File -> URI -> File conversion is universally accepted. Ref sbt#3088
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The URL encoding of Windows path that works out of the box is:
file:///C:/Users/foo
for path on the local machine.file:////unc/Users/foo
for UNC path.Even thought this is not the most modern/canonical encoding, it allows
file:///
to be used as a cross-platform prefixfile:///${user.home}
since on Mac and Linuxuser.home
would look like/Users/foo
, it would come out asfile:////Users/foo
.original PR
This adds support to convert from an
URL
to aFile
on Windows in several ways.This is an improvement over the constructor of
File
, which is unable to handleu0
andu2
cases:The error case for two slashes "URI has an authority component" shows up in many cases, most recently borking 0.13.14 in #3086. Note that it might be intuitive to encode file path by starting with
file://
similar tohttp://
, however this is specified by Microsoft to be an UNC path, so the URIfile://C:/Users/foo/.sbt/preloaded
is illegal. Since the authority component after//
, in this caseC:
should denote the remote host name.This complicates trying to specify sbt global base (default
~/.sbt/
) path in a cross platform way.The above original is incorrect because on Windows,
${user.home}
would returnC:\Users\foo\
. The solution is to encode without the prefix slashes likeu0
.Fixes #3086
Fixes #2150