-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Proposed API for canonical paths #23871
Comments
Should I expect to get some feedback so that I can get this out of api-needs-work? |
cc: @JeremyKuhne |
@carlreinke Sorry, missed this one. Can you please separate the canonical path API into a different issue? It will be hard to track the discussion otherwise. Both topics are of interest and I'll comment in detail once it is broken out. |
@JeremyKuhne Done. (Though I split them opposite of how you suggested.) |
Thanks for your work here! We need to call out explicit usage cases to make sure we've got the design right. What problem is this intended to solve? For this API in particular it is super important we're as detailed as possible. A problematic API, for example, is
One thing we might want to consider is extending
Would that address most of the scenarios? It is easier to explain and doesn't infer "identity" like canonicalize does. This does, however, have some problems (which are not unique to using GetFullPath):
For
Is that true? What resolves an input like that? GetFullPath() would be wrong if this is the case. Normalizing casing requires walking the input path segments afaik. Expensive, but I don't know of any way around that. One Windows API to look at to help inform this work is GetFinalPathNameByHandle. |
Sure! Fire up WSL and give it a try. :)
(Behavior is the same on Ubuntu, so it's not just a quirk of WSL.) |
Hmm- I need to set aside some time to fully understand this behavior. Windows claims to have implemented it's symbolic links just like Unix, I can't wrap my head around how this would manifest in Win32. To be honest, though, given the prior need for elevation my usage of symlinks has been pretty basic. :) |
Please consider for .NET 10! |
Rationale
Proposed API
Details
A canonical path
DirectorySeparatorChar
as a directory separator,.
and..
) and no empty path elements (ex./foo//bar
),The behavior of
..
with respect to symbolic links is platform dependent. On Windows, it removes the symbolic link element. On Linux, it removes an element of path that was resolved from the symbolic link.Examples:
C:\Users\All Users
is a symbolic link toC:\ProgramData
then the canonical form ofC:\Users\All Users\..\foo
isC:\Users\foo
./var/lock
is a symbolic link to/run/lock
then the canonical form of/var/lock/../foo
is/run/foo
.On Linux it is not always possible to preserve symbolic links while simplifying
..
. In these casesPath.GetCanonicalPath(string, bool)
will resolve the symbolic link regardless of the value ofpreserveSymbolicLinks
.For the purposes of this API, NTFS Junction Points are considered to be like Linux bind mounts and are not considered to be symbolic links.
Since most of the members of
Path
do not do I/O there might be some objection to addingGetCanonicalPath
toPath
. There is at least one existing method that does do I/O —Path.GetTempFileName
— so it would not be the first.Open Questions
GetCanonicalPath
handle paths in\\?\
and\\.\
?\\?\
path if and only if the input path was in\\?\
.\\.\
.GetCanonicalPath
do if the path does not exist?Related Issues
See Also
Updates
SymbolicLinkOption
withbool
.The text was updated successfully, but these errors were encountered: