diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 85bcb0bf7..fd5d040be 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-latest, macos-latest] steps: - uses: actions/checkout@v1 diff --git a/src/EmbedIO/Files/FileSystemProvider.cs b/src/EmbedIO/Files/FileSystemProvider.cs index 2f221492d..26f8f2131 100644 --- a/src/EmbedIO/Files/FileSystemProvider.cs +++ b/src/EmbedIO/Files/FileSystemProvider.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Threading; using EmbedIO.Utilities; @@ -18,6 +19,9 @@ public class FileSystemProvider : IDisposable, IFileProvider /// /// Initializes a new instance of the class. /// + /// + /// OSX doesn't support , the parameter will be always . + /// /// The file system path. /// if files and directories in /// are not expected to change during a web server's @@ -28,10 +32,17 @@ public class FileSystemProvider : IDisposable, IFileProvider public FileSystemProvider(string fileSystemPath, bool isImmutable) { FileSystemPath = Validate.LocalPath(nameof(fileSystemPath), fileSystemPath, true); - IsImmutable = isImmutable; + IsImmutable = isImmutable || RuntimeInformation.IsOSPlatform(OSPlatform.OSX); - if (!IsImmutable) - _watcher = new FileSystemWatcher(FileSystemPath); + try + { + if (!IsImmutable) + _watcher = new FileSystemWatcher(FileSystemPath); + } + catch (PlatformNotSupportedException) + { + IsImmutable = true; + } } /// @@ -84,7 +95,7 @@ public void Start(CancellationToken cancellationToken) { // Unescape the url before continue urlPath = Uri.UnescapeDataString(urlPath); - + // Bail out early if the path is a rooted path, // as Path.Combine would ignore our base path. // See https://docs.microsoft.com/en-us/dotnet/api/system.io.path.combine @@ -165,10 +176,10 @@ private static MappedResourceInfo GetMappedFileInfo(IMimeTypeProvider mimeTypePr private static MappedResourceInfo GetMappedFileInfo(IMimeTypeProvider mimeTypeProvider, FileInfo info) => MappedResourceInfo.ForFile( - info.FullName, - info.Name, - info.LastWriteTimeUtc, - info.Length, + info.FullName, + info.Name, + info.LastWriteTimeUtc, + info.Length, mimeTypeProvider.GetMimeType(info.Extension)); private static MappedResourceInfo GetMappedDirectoryInfo(string localPath) @@ -180,7 +191,7 @@ private static MappedResourceInfo GetMappedDirectoryInfo(DirectoryInfo info) private static MappedResourceInfo GetMappedResourceInfo(IMimeTypeProvider mimeTypeProvider, FileSystemInfo info) => info is DirectoryInfo directoryInfo ? GetMappedDirectoryInfo(directoryInfo) - : GetMappedFileInfo(mimeTypeProvider, (FileInfo)info); + : GetMappedFileInfo(mimeTypeProvider, (FileInfo) info); private void Watcher_ChangedOrDeleted(object sender, FileSystemEventArgs e) => ResourceChanged?.Invoke(e.FullPath); diff --git a/src/EmbedIO/WebModuleContainerExtensions-Files.cs b/src/EmbedIO/WebModuleContainerExtensions-Files.cs index c07ae1bab..b8bea1bcd 100644 --- a/src/EmbedIO/WebModuleContainerExtensions-Files.cs +++ b/src/EmbedIO/WebModuleContainerExtensions-Files.cs @@ -42,6 +42,9 @@ public static TContainer WithStaticFolder( /// a , and adds the latter to a module container, /// giving it the specified if not . /// + /// + /// OSX doesn't support , the parameter will be always . + /// /// The type of the module container. /// The on which this method is called. /// The name. diff --git a/test/EmbedIO.Tests/StaticFilesModuleTest.cs b/test/EmbedIO.Tests/StaticFilesModuleTest.cs index 4c12ff8fe..aea7289e2 100644 --- a/test/EmbedIO.Tests/StaticFilesModuleTest.cs +++ b/test/EmbedIO.Tests/StaticFilesModuleTest.cs @@ -7,6 +7,7 @@ using System.Net; using System.Net.Http; using System.Net.Http.Headers; +using System.Runtime.InteropServices; using System.Threading.Tasks; using EmbedIO.Testing; using EmbedIO.Utilities; @@ -84,6 +85,9 @@ public async Task TestHeadIndex() [Test] public async Task FileWritable() { + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + Assert.Ignore("OSX doesn't support FileSystemWatcher"); + var root = Path.GetTempPath(); var file = Path.Combine(root, "index.html"); File.WriteAllText(file, Resources.Index);