-
Notifications
You must be signed in to change notification settings - Fork 4k
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
TrimTrailingSeparators on GetRelativePath #52912
TrimTrailingSeparators on GetRelativePath #52912
Conversation
@@ -534,6 +534,9 @@ public static string GetRelativePath(string directory, string fullPath) | |||
{ | |||
string relativePath = string.Empty; | |||
|
|||
directory = TrimTrailingSeparators(directory); | |||
fullPath = TrimTrailingSeparators(fullPath); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is always terrifying to me. Is there a reason we have our own GetRelativePath? I thought this was something the platform provided. If we write our own, won't we always have the risk of just deviating and needing to continually patch like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this entirely and switch to https://docs.microsoft.com/en-us/dotnet/api/system.io.path.getrelativepath?view=net-5.0 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because Path.GetRelativePath doesn't exist in .NET Framework of .NET Standard I assume? @dotnet/roslyn-compiler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct. I don't know if it would be better to use the platform implementation on TFMs where it's available, and fall back to our own implementation otherwise, since if there are bugs with this it may make it harder to reproduce them.
As far as copying the platform implementation, that may help, if the implementation doesn't depend on too much stuff within dotnet/runtime. If it's practical to copy the tests for this method from dotnet/runtime repo that might be helpful too. I consider both to be up to the author's discretion here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that its would be much better if we called the underlying platform apis on .NET Core and newer. The question is whether we want #51602 to make 16.10. we basically have today and tomorrow to get this in if we do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we either use the platform method? or can we just dupe their code? I'm really wary about us seeming to have a home grown version with semantics i have no clue about.
{ | ||
var expected = ""; | ||
var result = PathUtilities.GetRelativePath(@"C:\A\B\", @"C:\A\B"); | ||
Assert.Equal(expected, result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of making this windows only, can we instead just build the string using the platform sepaarator? or, barring that, have some tests for non-windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d0462a1
to
e7b7556
Compare
Filed #52936 to resolve what the correct thing to do with our poor duplicate implementation of GetRelativePath |
Thank you 💜 |
@jmarolf hi. I am facing this issue now in a project of mine. I see you have a fix checked in. But how do we get it ? is there any workaround to this? I am kind of blocked in what i am doing. thoughts? |
fixes #51602