dotnet/runtime

Split polling functionality from PhysicalFilesWatcher into a separate type

Open

#48,602 opened on Feb 22, 2021

View on GitHub
 (2 comments) (2 reactions) (0 assignees)C# (5,445 forks)batch import
area-Extensions-FileSystemhelp wanted

Repository metrics

Stars
 (17,886 stars)
PR merge metrics
 (Avg merge 12d 11h) (661 merged PRs in 30d)

Description

Description

Related to https://github.com/dotnet/runtime/issues/17111

We have a polling implementation as a mode of https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.fileproviders.physical.physicalfileswatcher?view=dotnet-plat-ext-5.0 when pollForChanges is set true.

For this to actually be useful (and raise events like a normal file watcher) you also need to set UseActivePolling: https://github.com/dotnet/runtime/blob/8a52f1e948b6f22f418817ec1068f07b8dae2aa5/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFilesWatcher.cs#L109

Which can only be set by the UseActivePolling in the PhysicalFileProvider: https://github.com/dotnet/runtime/blob/8a52f1e948b6f22f418817ec1068f07b8dae2aa5/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFileProvider.cs#L163-L169

In addition the PhysicalFilesWatcher requires things like a FileSystemWatcher which is irrelevant when polling, fails to watch full paths which is also an unnecessary limitation if you don't have a "watch" tied to a root path, and is coupled to Physical implementation, which it need not be, and could interact through the FileSystem abstractions themselves (either IFileProvider, or IFileInfo/IDirectoryContents)

In addition to this, the current PollingFileChangeToken are PollingWildCardChangeToken are somewhat crippled as they can only poll and cannnot be easily made to raise events (we kept everything internal).

Related: https://github.com/dotnet/runtime/issues/36091

Contributor guide