Skip to content
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

Resolver.file mangles UNC paths #5596

Closed
batterseapower opened this issue Jun 9, 2020 · 3 comments · Fixed by sbt/librarymanagement#337
Closed

Resolver.file mangles UNC paths #5596

batterseapower opened this issue Jun 9, 2020 · 3 comments · Fixed by sbt/librarymanagement#337

Comments

@batterseapower
Copy link

If on Windows we do something like this:

sbt.Resolver.file("name", new File("//intra/live/foo"))(Patterns("[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"))

Then the resulting FileResolver is built with paths like "C:\intra\live\foo\[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]" i.e. the UNC path is replaced with the drive letter of the current working directory, which is definitely not what we want.

The cause of the problem is https://github.com/sbt/librarymanagement/blob/c3dca6880d7b129f708c8b59cf703e52fb4554e3/core/src/main/scala/sbt/librarymanagement/ResolverExtra.scala#L307

i.e.

new File(baseDirectory.toURI.normalize).getAbsolutePath

Because:

new File("//intra/live/foo").toURI() == new java.net.URI("file:////intra/live/foo")
new java.net.URI("file:////intra/live/foo").normalize() == new java.net.URI("file:/intra/live/foo")
new File(new java.net.URI("file:/intra/live/foo")) == new File("\\intra\\live\\foo")
new File("\\intra\\live\\foo").getAbsolutePath() == "C:\\intra\\live\\foo"

I think you can fix this by just dropping the use of normalize since new File(new File("//intra/live/foo").toURI()).getAbsolutePath() == "//intra/live/foo"

@eed3si9n eed3si9n transferred this issue from sbt/librarymanagement Jun 9, 2020
@eed3si9n
Copy link
Member

eed3si9n commented Jun 9, 2020

@batterseapower Thanks for the report.

I blogged about related topic a while back (http://eed3si9n.com/encoding-file-path-as-URI-reference). I'll compare to see what's happening in this code.

@batterseapower
Copy link
Author

Wow, that's a very comprehensive post. I hadn't considered that using nio.file.Path could be an alternative workaround.

eed3si9n added a commit to eed3si9n/librarymanagement that referenced this issue Jun 26, 2020
@eed3si9n
Copy link
Member

Here's my PR - sbt/librarymanagement#337

eed3si9n added a commit to eed3si9n/librarymanagement that referenced this issue Jun 26, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants