Updates code to account for MacOS as a UNIX platform

This commit is contained in:
BinaryAlley committed 2024-11-06 20:26:26 +02:00
1 parent d32f124147
commit 01decb27d5
4 files changed
+6 -8

No files matched your search

@@ -40,7 +40,7 @@ internal class FileSystemPermissionsService : IFileSystemPermissionsService // T
{
PlatformType platformType = _platformContextManager.GetCurrentContext().Platform;
if (platformType == PlatformType.Unix)
return CanAccessPathLinux(path.Path, accessMode);
return CanAccessPathUnix(path.Path, accessMode);
else if (platformType == PlatformType.Windows)
#pragma warning disable CA1416 // Validate platform compatibility
return CanAccessPathWindows(path.Path, accessMode, isFile);
@@ -50,13 +50,13 @@ internal class FileSystemPermissionsService : IFileSystemPermissionsService // T
}
/// <summary>
/// Checks if a the current user has access permissions on Linux for <paramref name="path"/>, with <paramref name="accessMode"/>.
/// Checks if a the current user has access permissions on Unix for <paramref name="path"/>, with <paramref name="accessMode"/>.
/// </summary>
/// <param name="path">The path for which to check the access.</param>
/// <param name="accessMode">The access mode in which to check that path access.</param>
/// <returns><see langword="true"/> if the current user has rights for the specified path and acccess mode, <see langword="false"/> otherwise.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when trying to check access for a mode that is not supported</exception>
private static bool CanAccessPathLinux(string path, FileAccessMode accessMode)
private static bool CanAccessPathUnix(string path, FileAccessMode accessMode)
{
AccessModes modes;
UnixFileSystemInfo fileInfo = new UnixFileInfo(path);
@@ -34,7 +34,7 @@ public class PlatformContextManager : IPlatformContextManager
{
// set a default context if none is set
if (_currentPlatformContext is null)
if (_operatingSystemInfo.IsOSPlatform(OSPlatform.Linux))
if (_operatingSystemInfo.IsOSPlatform(OSPlatform.Linux) || _operatingSystemInfo.IsOSPlatform(OSPlatform.OSX))
SetCurrentPlatform(PlatformType.Unix);
else
SetCurrentPlatform(PlatformType.Windows);