Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ public void GetDefaultBasePathForSources()

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34582", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)]
[SkipOnPlatform(TestPlatforms.Browser, "System.IO.FileSystem.Watcher is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.iOS | TestPlatforms.tvOS, "System.IO.FileSystem.Watcher is not supported on Browser/iOS/tvOS")]
public void CanEnumerateProviders()
{
var config = CreateBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ internal PhysicalFilesWatcher CreateFileWatcher()

FileSystemWatcher? watcher;
#if NETCOREAPP
// For browser we will proactively fallback to polling since FileSystemWatcher is not supported.
if (OperatingSystem.IsBrowser())
// For browser/iOS/tvOS we will proactively fallback to polling since FileSystemWatcher is not supported.
if (OperatingSystem.IsBrowser() || (OperatingSystem.IsIOS() && !OperatingSystem.IsMacCatalyst()) || OperatingSystem.IsTvOS())
Copy link
Member

@am11 am11 Aug 26, 2021

Choose a reason for hiding this comment

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

IMO, ideally we should have a runtime config like System.Globalization.Invariant corresponding to DOTNET_USE_POLLING_FILE_WATCHER environment variable; given how many different machine setups in practice are requiring fallback to polling even on Linux/macOS (see commit history / issues redirecting from aspnetcore when it broke on .NET 5 and still is broken since the fix was never backported..)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I agree. Something to keep in mind for .NET 7 but I'll keep this more focused change since we need to backport to .NET 6.

{
UsePollingFileWatcher = true;
UseActivePolling = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public PhysicalFilesWatcher(
if (fileSystemWatcher != null)
{
#if NETCOREAPP
if (OperatingSystem.IsBrowser())
if (OperatingSystem.IsBrowser() || (OperatingSystem.IsIOS() && !OperatingSystem.IsMacCatalyst()) || OperatingSystem.IsTvOS())
{
throw new PlatformNotSupportedException(SR.Format(SR.FileSystemWatcher_PlatformNotSupported, typeof(FileSystemWatcher)));
}
Expand Down Expand Up @@ -147,7 +147,7 @@ public IChangeToken CreateFileChangeToken(string filter)
}

IChangeToken changeToken = GetOrAddChangeToken(filter);
// We made sure that browser never uses FileSystemWatcher.
// We made sure that browser/iOS/tvOS never uses FileSystemWatcher.
#pragma warning disable CA1416 // Validate platform compatibility
TryEnableFileSystemWatcher();
#pragma warning restore CA1416 // Validate platform compatibility
Expand Down Expand Up @@ -275,6 +275,9 @@ protected virtual void Dispose(bool disposing)
}

[UnsupportedOSPlatform("browser")]
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
private void OnRenamed(object sender, RenamedEventArgs e)
{
// For a file name change or a directory's name change notify registered tokens.
Expand Down Expand Up @@ -308,12 +311,18 @@ ex is DirectoryNotFoundException ||
}

[UnsupportedOSPlatform("browser")]
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
private void OnChanged(object sender, FileSystemEventArgs e)
{
OnFileSystemEntryChange(e.FullPath);
}

[UnsupportedOSPlatform("browser")]
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
private void OnError(object sender, ErrorEventArgs e)
{
// Notify all cache entries on error.
Expand All @@ -324,6 +333,9 @@ private void OnError(object sender, ErrorEventArgs e)
}

[UnsupportedOSPlatform("browser")]
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
private void OnFileSystemEntryChange(string fullPath)
{
try
Expand All @@ -347,6 +359,9 @@ ex is SecurityException ||
}

[UnsupportedOSPlatform("browser")]
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
private void ReportChangeForMatchedEntries(string path)
{
if (string.IsNullOrEmpty(path))
Expand Down Expand Up @@ -384,6 +399,9 @@ private void ReportChangeForMatchedEntries(string path)
}

[UnsupportedOSPlatform("browser")]
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
private void TryDisableFileSystemWatcher()
{
if (_fileWatcher != null)
Expand All @@ -402,6 +420,9 @@ private void TryDisableFileSystemWatcher()
}

[UnsupportedOSPlatform("browser")]
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
private void TryEnableFileSystemWatcher()
{
if (_fileWatcher != null)
Expand Down
Loading