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 @@ -160,13 +160,21 @@ internal PhysicalFilesWatcher CreateFileWatcher()
{
string root = PathUtils.EnsureTrailingSlash(Path.GetFullPath(Root));

// When both UsePollingFileWatcher & UseActivePolling are set, we won't use a FileSystemWatcher.
FileSystemWatcher watcher = UsePollingFileWatcher && UseActivePolling ? null :
FileSystemWatcher watcher;
#if NETCOREAPP
OperatingSystem.IsBrowser() ? throw new PlatformNotSupportedException(SR.Format(SR.FileSystemWatcher_PlatformNotSupported, typeof(FileSystemWatcher))) : new FileSystemWatcher(root);
#else
new FileSystemWatcher(root);
// For browser we will proactively fallback to polling since FileSystemWatcher is not supported.
if (OperatingSystem.IsBrowser())
{
UsePollingFileWatcher = true;
UseActivePolling = true;
watcher = null;
}
else
#endif
{
// When UsePollingFileWatcher & UseActivePolling are set, we won't use a FileSystemWatcher.
watcher = UsePollingFileWatcher && UseActivePolling ? null : new FileSystemWatcher(root);
}

return new PhysicalFilesWatcher(root, watcher, UsePollingFileWatcher, _filters)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@
<value>Unexpected type of FileSystemInfo</value>
</data>
<data name="FileSystemWatcher_PlatformNotSupported" xml:space="preserve">
<value>The type {0} is not supported on this platform, use polling instead.</value>
<value>The type '{0}' is not supported on this platform, use polling instead.</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Xunit;

[assembly: SkipOnPlatform(TestPlatforms.Browser, "Microsoft.Extensions.FileProviders.Physical is not supported on Browser")]
using Xunit;
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>Microsoft.Extensions.FileProviders.Physical</RootNamespace>
<TargetFrameworks>$(NetCoreAppCurrent);net461</TargetFrameworks>
<EnableDefaultItems>true</EnableDefaultItems>
<IgnoreForCI Condition="'$(TargetOS)' == 'Browser'">true</IgnoreForCI>
<IncludePlatformAttributes>false</IncludePlatformAttributes>
</PropertyGroup>

<ItemGroup>
<Compile Include="$(CommonTestPath)System\Threading\Tasks\TaskTimeoutExtensions.cs"
Link="Common\System\Threading\Tasks\TaskTimeoutExtensions.cs" />
<TrimmerRootDescriptor Include="$(ILLinkDescriptorsPath)ILLink.Descriptors.Castle.xml" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != '$(NetCoreAppCurrent)'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ public void GetFileInfoReturnsFileInfoWhenExclusionDisabled()

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34582", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)]
[SkipOnPlatform(TestPlatforms.Browser, "Browser always uses Active Polling which doesn't return the same instance between multiple calls to Watch(string)")]
public void TokenIsSameForSamePath()
{
using (var root = new DisposableFileSystem())
Expand All @@ -348,6 +349,7 @@ public void TokenIsSameForSamePath()

[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")]
public async Task TokensFiredOnFileChange()
{
using (var root = new DisposableFileSystem())
Expand Down Expand Up @@ -378,6 +380,7 @@ public async Task TokensFiredOnFileChange()

[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")]
public async Task TokenCallbackInvokedOnFileChange()
{
using (var root = new DisposableFileSystem())
Expand Down Expand Up @@ -414,6 +417,7 @@ public async Task TokenCallbackInvokedOnFileChange()

[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")]
public async Task WatcherWithPolling_ReturnsTrueForFileChangedWhenFileSystemWatcherDoesNotRaiseEvents()
{
using (var root = new DisposableFileSystem())
Expand Down Expand Up @@ -444,6 +448,7 @@ public async Task WatcherWithPolling_ReturnsTrueForFileChangedWhenFileSystemWatc

[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")]
public async Task WatcherWithPolling_ReturnsTrueForFileRemovedWhenFileSystemWatcherDoesNotRaiseEvents()
{
using (var root = new DisposableFileSystem())
Expand Down Expand Up @@ -476,6 +481,7 @@ public async Task WatcherWithPolling_ReturnsTrueForFileRemovedWhenFileSystemWatc

[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")]
public async Task TokensFiredOnFileDeleted()
{
using (var root = new DisposableFileSystem())
Expand Down Expand Up @@ -787,6 +793,7 @@ public void GetDirectoryContentsReturnsFilesWhenExclusionDisabled()

[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")]
public async Task FileChangeTokenNotNotifiedAfterExpiry()
{
using (var root = new DisposableFileSystem())
Expand Down Expand Up @@ -819,6 +826,7 @@ public async Task FileChangeTokenNotNotifiedAfterExpiry()

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34582", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)]
[SkipOnPlatform(TestPlatforms.Browser, "Browser always uses Active Polling which doesn't return the same instance between multiple calls to Watch(string)")]
public void TokenIsSameForSamePathCaseInsensitive()
{
using (var root = new DisposableFileSystem())
Expand All @@ -835,6 +843,7 @@ public void TokenIsSameForSamePathCaseInsensitive()

[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")]
public async Task CorrectTokensFiredForMultipleFiles()
{
using (var root = new DisposableFileSystem())
Expand Down Expand Up @@ -868,6 +877,7 @@ public async Task CorrectTokensFiredForMultipleFiles()

[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")]
public async Task TokenNotAffectedByExceptions()
{
using (var root = new DisposableFileSystem())
Expand Down Expand Up @@ -975,6 +985,7 @@ public void NoopChangeTokenForAbsolutePathFilters()

[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")]
public async Task TokenFiredOnCreation()
{
using (var root = new DisposableFileSystem())
Expand All @@ -1000,6 +1011,7 @@ public async Task TokenFiredOnCreation()

[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")]
public async Task TokenFiredOnDeletion()
{
using (var root = new DisposableFileSystem())
Expand All @@ -1025,6 +1037,7 @@ public async Task TokenFiredOnDeletion()

[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")]
public async Task TokenFiredForFilesUnderPathEndingWithSlash()
{
using (var root = new DisposableFileSystem())
Expand Down Expand Up @@ -1079,6 +1092,7 @@ public async Task TokenFiredForRelativePathStartingWithSlash_Windows(string slas
[InlineData("///")]
// Testing Unix specific behaviour on leading slashes.
[PlatformSpecific(TestPlatforms.AnyUnix)]
[SkipOnPlatform(TestPlatforms.Browser, "System.IO.FileSystem.Watcher is not supported on Browser")]
public async Task TokenFiredForRelativePathStartingWithSlash_Unix(string slashes)
{
await TokenFiredForRelativePathStartingWithSlash(slashes);
Expand Down Expand Up @@ -1121,6 +1135,7 @@ public async Task TokenNotFiredForInvalidPathStartingWithSlash_Windows(string sl
[InlineData("/\0/")]
// Testing Unix specific behaviour on leading slashes.
[PlatformSpecific(TestPlatforms.AnyUnix)]
[SkipOnPlatform(TestPlatforms.Browser, "System.IO.FileSystem.Watcher is not supported on Browser")]
public async Task TokenNotFiredForInvalidPathStartingWithSlash_Unix(string slashes)
{
await TokenNotFiredForInvalidPathStartingWithSlash(slashes);
Expand Down Expand Up @@ -1152,6 +1167,7 @@ private async Task TokenNotFiredForInvalidPathStartingWithSlash(string slashes)

[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")]
public async Task TokenFiredForGlobbingPatternsPointingToSubDirectory()
{
using (var root = new DisposableFileSystem())
Expand Down Expand Up @@ -1185,6 +1201,7 @@ public async Task TokenFiredForGlobbingPatternsPointingToSubDirectory()

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34582", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)]
[SkipOnPlatform(TestPlatforms.Browser, "Browser always uses Active Polling which doesn't return the same instance between multiple calls to Watch(string)")]
public void TokensWithForwardAndBackwardSlashesAreSame()
{
using (var root = new DisposableFileSystem())
Expand All @@ -1201,6 +1218,7 @@ public void TokensWithForwardAndBackwardSlashesAreSame()

[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")]
public async Task TokensFiredForOldAndNewNamesOnRename()
{
using (var root = new DisposableFileSystem())
Expand Down Expand Up @@ -1230,6 +1248,7 @@ public async Task TokensFiredForOldAndNewNamesOnRename()

[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")]
public async Task TokensFiredForNewDirectoryContentsOnRename()
{
var tcsShouldNotFire = new TaskCompletionSource<object>();
Expand Down Expand Up @@ -1303,6 +1322,7 @@ void Fail(object state)

[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")]
public async Task TokenNotFiredForFileNameStartingWithPeriod()
{
using (var root = new DisposableFileSystem())
Expand Down Expand Up @@ -1370,6 +1390,7 @@ public async Task TokensNotFiredForHiddenAndSystemFiles()

[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")]
public async Task TokensFiredForAllEntriesOnError()
{
using (var root = new DisposableFileSystem())
Expand Down Expand Up @@ -1398,6 +1419,7 @@ public async Task TokensFiredForAllEntriesOnError()

[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")]
public async Task WildCardToken_RaisesEventsForNewFilesAdded()
{
// Arrange
Expand All @@ -1424,6 +1446,7 @@ public async Task WildCardToken_RaisesEventsForNewFilesAdded()

[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")]
public async Task WildCardToken_RaisesEventsWhenFileSystemWatcherDoesNotFire()
{
// Arrange
Expand Down Expand Up @@ -1473,6 +1496,7 @@ public void UsePollingFileWatcher_FileWatcherNull_SetsSuccessfully()
}

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "System.IO.FileSystem.Watcher is not supported on Browser")]
public void UsePollingFileWatcher_FileWatcherNotNull_SetterThrows()
{
// Arrange
Expand All @@ -1493,6 +1517,7 @@ public void UsePollingFileWatcher_FileWatcherNotNull_SetterThrows()
}

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "System.IO.FileSystem.Watcher is not supported on Browser")]
public void UsePollingFileWatcher_FileWatcherNotNull_ReturnsFalse()
{
// Arrange
Expand Down Expand Up @@ -1589,6 +1614,7 @@ public void CreateFileWatcher_CreatesWatcherWithPollingAndActiveFlags()
[InlineData(false)]
[InlineData(true)]
[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")]
public async Task CanDeleteWatchedDirectory(bool useActivePolling)
{
using (var root = new DisposableFileSystem())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class PhysicalFilesWatcherTests
private const int WaitTimeForTokenToFire = 500;

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "System.IO.FileSystem.Watcher is not supported on Browser")]
public void CreateFileChangeToken_DoesNotAllowPathsAboveRoot()
{
using (var root = new DisposableFileSystem())
Expand All @@ -37,6 +38,7 @@ public void CreateFileChangeToken_DoesNotAllowPathsAboveRoot()

[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")]
public async Task HandlesOnRenamedEventsThatMatchRootPath()
{
using (var root = new DisposableFileSystem())
Expand Down Expand Up @@ -129,6 +131,7 @@ public void RaiseChangeEvents_CancelsAndRemovesMultipleChangedTokens()
}

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "System.IO.FileSystem.Watcher is not supported on Browser")]
public void GetOrAddFilePathChangeToken_AddsPollingChangeTokenWithCancellationToken_WhenActiveCallbackIsTrue()
{
using (var root = new DisposableFileSystem())
Expand All @@ -155,6 +158,7 @@ public void GetOrAddFilePathChangeToken_AddsPollingChangeTokenWithCancellationTo
}

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "System.IO.FileSystem.Watcher is not supported on Browser")]
public void GetOrAddFilePathChangeToken_AddsPollingChangeTokenWhenPollingIsEnabled()
{
using (var root = new DisposableFileSystem())
Expand All @@ -179,6 +183,7 @@ public void GetOrAddFilePathChangeToken_AddsPollingChangeTokenWhenPollingIsEnabl
}

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "System.IO.FileSystem.Watcher is not supported on Browser")]
public void GetOrAddFilePathChangeToken_DoesNotAddsPollingChangeTokenWhenCallbackIsDisabled()
{
using (var root = new DisposableFileSystem())
Expand All @@ -193,6 +198,7 @@ public void GetOrAddFilePathChangeToken_DoesNotAddsPollingChangeTokenWhenCallbac
}

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "System.IO.FileSystem.Watcher is not supported on Browser")]
public void GetOrAddWildcardChangeToken_AddsPollingChangeTokenWithCancellationToken_WhenActiveCallbackIsTrue()
{
using (var root = new DisposableFileSystem())
Expand Down