dotnet/runtime

Split polling functionality from PhysicalFilesWatcher into a separate type

Open

#48.602 aperta il 22 feb 2021

Vedi su GitHub
 (2 commenti) (2 reazioni) (0 assegnatari)C# (5445 fork)batch import
area-Extensions-FileSystemhelp wanted

Metriche repository

Star
 (17.886 star)
Metriche merge PR
 (Merge medio 12g 11h) (661 PR mergiate in 30 g)

Descrizione

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

Guida contributor