dotnet/runtime

Split polling functionality from PhysicalFilesWatcher into a separate type

Open

#48,602 建立於 2021年2月22日

在 GitHub 查看
 (2 留言) (2 反應) (0 負責人)C# (5,445 fork)batch import
area-Extensions-FileSystemhelp wanted

倉庫指標

Star
 (17,886 star)
PR 合併指標
 (平均合併 12天 11小時) (30 天內合併 661 個 PR)

描述

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

貢獻者指南