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

fixed workspaces issues due to non-canonical manifest path #7729

Closed

Conversation

stefanhoelzl
Copy link

this PR fixes #7686

comparisons with the root manifest path failed even if paths were identical.
This was due to a comparison with a non-canonical root manifest path with the canonical one.

This PR canonicalizes the manifest path when a Workspace is created, so that all future comparison are using the canonical manifest path.

Before two identical path, just represented differently, where not equal e.g. a/../a != a
With this PR the comparison looks like this a == a, which is as expected equal

@rust-highfive
Copy link

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 20, 2019
@stefanhoelzl
Copy link
Author

oh, looks like under windows the canonical path is a UNC path, see rust-lang/rust#42869
that's why the tests under windows are failing.

@alexcrichton
Copy link
Member

Thanks for the PR! Unfortunately though this sort of user-space canonicalization is very tricky and we try to avoid it wherever we can. Can this same issue be solved with syscalls or some other form of path comparison which doesn't require manually interpreting the path?

@stefanhoelzl
Copy link
Author

like I said fs::canonicalize does a normalization, but also creates UNC paths on windows.
There is this dunce crate which make a regular path out of UNC paths, but this would add another dependency.

I am not aware of other ways, but I am pretty new to rust, so maybe there is another solution

@ehuss
Copy link
Contributor

ehuss commented Jan 7, 2020

dunce looks interesting, though it is a little concerning it is all user-space. Dealing with this properly is extraordinarily difficult, but I'm not sure if we need to aim for 100% perfection.

One of the fundamental questions is whether or not the normalization should follow symlinks. I'm not sure I have a good answer to that. Using symlinks in a workspace seems likely to be problematic.

Cargo has normalize_path, which is a somewhat simplified version. I suspect it is somewhat wrong in some cases, but again getting perfect is a monumental task. I would feel more comfortable replacing that with something that is known to be more correct.

One thing I've been curious about is whether or not GetFullPathNameW would be a good alternative to GetFinalPathNameByHandle.

@alexcrichton
Copy link
Member

I think in general we've been bitten enough by any form of canonicalization that we want to avoid adding more canonicalization to Cargo. Can we perhaps solve this by not comparing paths? Is there something else we can do in Cargo?

@stefanhoelzl
Copy link
Author

I was not aware of paths::normalize_path in cargo, but I tried it and it does the job, so my resolve_path method is not necessary, but we would still do the sanitation in user space.
Still would be the easiest fix and would not introduce some new canonicalization.

Another interesting crate could be same-file it compares files by comparing their inode-number on unix respectively the file_index on windows.

@alexcrichton
Copy link
Member

Looking through some paths the normalization logic is actually already applied for --manifest-path arguments, so I think this may perhaps be only related to --path of the cargo install command? If that's the case can the fix be applied locally to just that one location to avoid repeated calls to normalization? Ideally we want the normalization to be as far away as possible as well to reduce implicit reliance on it within Cargo.

@bors
Copy link
Collaborator

bors commented Jun 5, 2020

☔ The latest upstream changes (presumably #8321) made this pull request unmergeable. Please resolve the merge conflicts.

@alexcrichton
Copy link
Member

This has been here for quite some time now so I'm going to go ahead and close this, feel free to resubmit though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Workspace path is not fully resolved
5 participants