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

On windows, os.relativePath returns path as is when roots are different #12329

Merged
merged 4 commits into from
Oct 7, 2019

Conversation

demotomohiro
Copy link
Contributor

Before making this PR, os.relativePath returns wrong path when a root of path and a root of base are different.

import os

echo relativePath(r"c:\foo", r"d:\bar")
echo relativePath(r"\\foo\bar\x", r"\\foo\baz\")

output:

..\..\c:\foo
..\bar\x

This PR uses PathIsSameRootW or PathIsSameRootA windows API to compare roots of input paths.
If they were not same root, returns path as is.
But PathIsSameRootW or PathIsSameRootA seems don't support DOS device paths.

This code test PathIsSameRootW.
https://gist.github.com/demotomohiro/81702d8a0bf951d6a46b9954093d69bb

APIs in pathcch.h header supports DOS device paths but there is not API to compare root of paths and they are only available on windows 8 or newer.

Implementing PathIsSameRoot that supports DOS device paths can be larger code than this PR.

@demotomohiro
Copy link
Contributor Author

I changed code so that os.relativePath compare roots of input paths without using windows API.
Because windows API is not available at compile time or nimscript and os.relativePath can return wrong relative at compile time.

@Araq Araq merged commit 509f53b into nim-lang:devel Oct 7, 2019
@demotomohiro demotomohiro deleted the fixrelativepath branch October 26, 2019 08:42
alehander92 pushed a commit to alehander92/Nim that referenced this pull request Dec 2, 2019
…nt (nim-lang#12329)

* On windows, os.relativePath returns path as is when roots are different
* Implement os.sameRoot without windows API
* Fix compile error when compiling lib/nimhcr.nim
* Fix compile error when compiling lib/nimhcr.nim on Windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants