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

TrimTrailingSeparators on GetRelativePath #52912

Merged
merged 3 commits into from
Apr 26, 2021

Conversation

jmarolf
Copy link
Contributor

@jmarolf jmarolf commented Apr 26, 2021

fixes #51602

@jmarolf jmarolf requested a review from a team as a code owner April 26, 2021 12:49
@RikkiGibson RikkiGibson self-assigned this Apr 26, 2021
@@ -534,6 +534,9 @@ public static string GetRelativePath(string directory, string fullPath)
{
string relativePath = string.Empty;

directory = TrimTrailingSeparators(directory);
fullPath = TrimTrailingSeparators(fullPath);

Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a 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);
Copy link
Member

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?

Copy link
Member

@tmat tmat left a comment

Choose a reason for hiding this comment

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

🕐

Copy link
Member

@tmat tmat left a comment

Choose a reason for hiding this comment

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

:shipit:

@jmarolf jmarolf force-pushed the bugfix/namespace-path-index-out-of-range branch from d0462a1 to e7b7556 Compare April 26, 2021 22:17
@jmarolf
Copy link
Contributor Author

jmarolf commented Apr 26, 2021

Filed #52936 to resolve what the correct thing to do with our poor duplicate implementation of GetRelativePath

@jmarolf jmarolf enabled auto-merge April 26, 2021 22:51
@jmarolf jmarolf merged commit 7dd737d into dotnet:main Apr 26, 2021
@ghost ghost added this to the Next milestone Apr 26, 2021
@benaadams
Copy link
Member

Thank you 💜

@lohithgn
Copy link

lohithgn commented May 1, 2021

@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?
thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CSharpMatchFolderAndNamespaceDiagnosticAnalyzer throws exception
7 participants