-
Notifications
You must be signed in to change notification settings - Fork 129
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
Error converting relative paths to absolute paths in Windows if relative path has leading slash or backslash #2359
Comments
I found |
BTW, this bug also manifests in the following situation: A philwalk@d5 ~/workspace/os-lib-phil
$ /opt/ue/jsrc/scalaCliBug.sc
[error] File not found: C:\Users\philwalk\workspace\os-lib-phil\opt\ue\jsrc\scalaCliBug.sc The same invocation with an explicit drive letter works. I have a |
Thanks for reporting! I see that you already created an issue in os-lib. There is nothing currently we can do in Scala CLI, closing in favour of com-lihaoyi/os-lib#201 |
I'd like to verify that this is fixed by com-lihaoyi/os-lib#202. |
Och wait, I think I lost the fact that the issue is connected to scala-cli usage of os-lib. The issue you reported seemed only relevant to os-lib itself. How did this show up in scala-cli? When using |
This bug causes any path with a leading slash to crash, whether in a script or on the command-line. Generally speaking, The |
Ok sure! We can wait for the os-lib to be released with the fix or try to figure out a workaround ourselves if that is not accepted. Sorry for misunderstanding the issue at hand. You could try releasing os-lib locally, changing it in https://github.com/VirtusLab/scala-cli/blob/main/project/deps.sc#L141 and running |
Now that
It does seem to fix this issue, although I've only done a very superficial amount of manual testing. |
I was able to build in .github/scripts/generate-native-image.sh I'll play with it awhile and report back. |
I created a PR #2516 that fixes this issue, and one other |
* fix for #2359, drive-relative paths accepted in Windows SHELL environments * added anti-regression test handling of drive-relative for os.Path * fix classpath-split regex String to accept either forward slash or backslash * added integration tests for JAVA_HOME setting to RunScriptTestDefinitions.scala * apply suggested changes * fix for cli.base-image.nativeImage in Windows * fix JAVA_HOME test; tweak mill script * Apply suggestions from code review --------- Co-authored-by: Piotr Chabelski <[email protected]>
Version(s)
Describe the bug
The following idiom is intended to convert a relative path to an absolute path:
This works as expected unless
relativeDir
arg has a leading slash or backslash. Although such a path is absolute everywhere else, inWindows
it's technically a relative path, but one that can only be made absolute by prefixing a drive letter. If not specified, the current working drive (typicallyC:
) is assumed. It's a type of relative path that cannot be resolved by prefixingpwd
. It resembles an absolute path on other platforms, and in practice, it's often seen that way, particularly on a system with a single drive, and especially by developers mostly familiar with other platforms.The proposed
os-lib
term for this type ofWindows
path isdrive-relative
. See com-lihaoyi/os-lib#202For relative paths that are
drive-relative
, the code above accidentally works as expected ifpwd
=='C:\'
or similar.For most values of
pwd
, it produces an incorrect result, and differs from the behavior ofjava.nio.file.Paths.get()
.Windows paths are described here: windows-file-path-formats. A reference to what I'm calling
drive-relative
is here.To Reproduce
The following script shows the problem and a solution for interpreting
root-relative-paths
in Windows.The output of the script when
pwd
=='F:\data'
:This result shows an incorrect value for
os.root
, if it's supposed to match environment variableSystemDrive
.Here's the output when
pwd
=='C:\Users\philwalk\workspace\scala-cli'
:In this case,
os.root
may be accidentally correct.Another way this bug manifests, when using the following
scala-cli
hashbang:#!/usr/bin/env -S scala-cli shebang
If the path referenced by
JAVA_HOME
does not include a drive letter, the following crash occurs:The workaround is to prefix various things on the command ine with the current working drive (
"C:"
in this example).So instead of this:
the command line must be issued like this (extra stuff in bold):
JAVA_HOME=C:$JAVA_HOME C:/opt/ue/jsrc/scalaCliBug.sc
After the
os-lib
fix is available, the same command line can be used inWindows
as on other platforms.Expected behaviour
If a path has a leading slash or backslash, convert it to an absolute path by prefixing the default drive letter.
This is also how
root-relative-paths
are interpreted inCMD.EXE
and everywhere.The text was updated successfully, but these errors were encountered: