Skip to content

Convert relative to absolute paths in link resolving #3

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

Merged
merged 1 commit into from
Nov 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion clr_loader/hostfxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def __init__(self, runtime_config, dotnet_root=None):
raise RuntimeError("Can not determine dotnet root")

try:
dotnet_path = os.readlink(dotnet_path)
dotnet_tmp_path = os.readlink(dotnet_path)
if os.path.isabs(dotnet_tmp_path):
dotnet_path = dotnet_tmp_path
else:
dotnet_path = os.path.abspath(os.path.join(os.path.dirname(dotnet_path), dotnet_tmp_path))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't simply doing os.path.abspath(os.readlink(dotnet_path)) be enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought about that. I'll try it later. Wasn't sure where abspath will base on. So I wanted to be sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I tried that now and it didn't work. Because:

os.path.abspath(path)

Return a normalized absolutized version of the pathname path. On most platforms, this is equivalent to calling the function normpath() as follows: normpath(join(os.getcwd(), path))

So what abspath does is to take the current working directy (where you started the script) and apply normpath(join(os.getcwd(), path)) .

That's why you would need all the fancy if else stuff. So in my case:
dotnet_root was /usr/bin/dotnet which was a symlink to ../share/dotnet/dotnet that was being taken by the abspath and concatenated onto my user directory /home/bneumann/pythonnet/clr-loader/share/dotnet/dotnet

except OSError:
pass

Expand Down