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

Fixing PhysicalFilesWatcher path maintenance (Issue #71386) #72041

Closed
wants to merge 5 commits into from

Conversation

turnyanszki
Copy link
Contributor

@turnyanszki turnyanszki commented Jul 12, 2022

#if NET5_0_OR_GREATER is needed beacuse the project is targeting .net framwork for some reason (analyzers maybe).
All project should be refactored at this lib some point in my opinion.
fixes #71386

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jul 12, 2022
@radical
Copy link
Member

radical commented Jul 12, 2022

@turnyanszki In the PR description, could you please describe the issue that you are fixing here? Also, add a short title for the PR. And reference any link for the issue, if there is one.

@ghost
Copy link

ghost commented Jul 12, 2022

Tagging subscribers to this area: @dotnet/area-system-configuration
See info in area-owners.md if you want to be subscribed.

Issue Details

#if NET5_0_OR_GREATER is needed beacuse the project is targeting .net framwork for some reason (analyzers maybe).
All project should be refactored at this lib some point in my opinion.

Author: turnyanszki
Assignees: -
Labels:

area-System.Configuration, community-contribution

Milestone: -

@turnyanszki
Copy link
Contributor Author

@turnyanszki In the PR description, could you please describe the issue that you are fixing here? Also, add a short title for the PR. And reference any link for the issue, if there is one.

There is a link in the commit to the issue.

@turnyanszki turnyanszki changed the title Issue 71386 Fixing FileChangeTracker path maintenance (Issue #71386) Jul 12, 2022
@turnyanszki turnyanszki changed the title Fixing FileChangeTracker path maintenance (Issue #71386) Fixing PhysicalFileWatcher path maintenance (Issue #71386) Jul 12, 2022
@turnyanszki turnyanszki changed the title Fixing PhysicalFileWatcher path maintenance (Issue #71386) Fixing PhysicalFilesWatcher path maintenance (Issue #71386) Jul 12, 2022
@ghost
Copy link

ghost commented Jul 20, 2022

Tagging subscribers to this area: @dotnet/area-extensions-filesystem
See info in area-owners.md if you want to be subscribed.

Issue Details

#if NET5_0_OR_GREATER is needed beacuse the project is targeting .net framwork for some reason (analyzers maybe).
All project should be refactored at this lib some point in my opinion.
fixes #71386

Author: turnyanszki
Assignees: -
Labels:

area-Extensions-FileSystem, community-contribution

Milestone: -

@danmoseley
Copy link
Member

@jozkee could you please give an idea when you will be able to review? This change seems small.

@eerhardt
Copy link
Member

eerhardt commented Sep 6, 2022

@turnyanszki - looks like the new test you added to verify the bug fix is failing on .NET Framework. This is because you are only adding code for #if NET5_0_OR_GREATER. You need to also fix the bug for .NET Framework.

@turnyanszki
Copy link
Contributor Author

@turnyanszki - looks like the new test you added to verify the bug fix is failing on .NET Framework. This is because you are only adding code for #if NET5_0_OR_GREATER. You need to also fix the bug for .NET Framework.

I dont want to implement the whole Path.GetFullPath method myself, and it does not exists in .NET Framework.
Any suggestions?

…PhysicalFilesWatcher.cs

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
@eerhardt
Copy link
Member

I dont want to implement the whole Path.GetFullPath method myself, and it does not exists in .NET Framework.
Any suggestions?

Looking at Path.GetFullPath, the trickiest part is the if (IsPathFullyQualified(path)) method:

public static string GetFullPath(string path, string basePath)
{
ArgumentNullException.ThrowIfNull(path);
ArgumentNullException.ThrowIfNull(basePath);
if (!IsPathFullyQualified(basePath))
throw new ArgumentException(SR.Arg_BasePathNotFullyQualified, nameof(basePath));
if (basePath.Contains('\0') || path.Contains('\0'))
throw new ArgumentException(SR.Argument_NullCharInPath);
if (IsPathFullyQualified(path))
return GetFullPathInternal(path);
return GetFullPathInternal(CombineInternal(basePath, path));
}

This method is available on netstandard2.0 or .NET Framework. However, looking at the callers of this method, it call comes from CreateFileChildToken here:

public IChangeToken CreateFileChangeToken(string filter)
{
ThrowHelper.ThrowIfNull(filter);
filter = NormalizePath(filter);
// Absolute paths and paths traversing above root not permitted.
if (Path.IsPathRooted(filter) || PathUtils.PathNavigatesAboveRoot(filter))
{
return NullChangeToken.Singleton;
}
IChangeToken changeToken = GetOrAddChangeToken(filter);

Which verifies that the filter string isn't a rooted path. So I believe you can just Combine the two paths, and call GetFullPath on the result. That should be the same on .NET Framework.

Comment on lines +178 to +181
#if NETCOREAPP
var absolutePath = Path.GetFullPath(filePath, _root);
filePath = absolutePath.Substring(_root.Length);
#endif
Copy link
Member

Choose a reason for hiding this comment

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

@eerhardt suggestion, this should work for .NET Framework too:

Suggested change
#if NETCOREAPP
var absolutePath = Path.GetFullPath(filePath, _root);
filePath = absolutePath.Substring(_root.Length);
#endif
#if NETCOREAPP
string absolutePath = Path.GetFullPath(filePath, _root);
#else
string absolutePath = Path.GetFullPath(Path.Combine(_root, filePath));
#endif
filePath = absolutePath.Substring(_root.Length);

@@ -987,6 +987,41 @@ void ReloadLoop()
}
}

[Fact]
public async Task ReloadingFileFiresOnChangeEvent()
Copy link
Member

Choose a reason for hiding this comment

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

This test should be a Theory and you should put ./reload.json and reload.json as InlineData.

@ghost ghost added the needs-author-action An issue or pull request that requires more info or actions from the author. label Oct 10, 2022
@ghost ghost added the no-recent-activity label Oct 25, 2022
@ghost
Copy link

ghost commented Oct 25, 2022

This pull request has been automatically marked no-recent-activity because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will remove no-recent-activity.

@ghost
Copy link

ghost commented Nov 8, 2022

This pull request will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the pull request, but please note that it will be locked if it remains inactive for another 30 days.

@ghost ghost closed this Nov 8, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2022
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Extensions-FileSystem community-contribution Indicates that the PR has been added by a community member needs-author-action An issue or pull request that requires more info or actions from the author. no-recent-activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ConfigurationBuilder.AddJsonFile can't fire OnChange event using relative paths
6 participants