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 @@ -174,7 +174,7 @@ public void Constructor1_ValueAsCodebaseArgument_ShouldSetAssemblyProperty()
});
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsFileLockingEnabled))]
public void Constructor1_LockedFileAsCodeBaseArgument_ShouldThrowFileLoad()
{
AssemblyCatalogConstructorTests.Constructor_LockedFileAsCodeBaseArgument_ShouldThrowIOException((s) =>
Expand Down Expand Up @@ -273,7 +273,7 @@ public void Constructor2_ValueAsCodebaseArgument_ShouldSetAssemblyProperty()
});
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsFileLockingEnabled))]
public void Constructor2_LockedFileAsCodeBaseArgument_ShouldThrowFileLoad()
{
AssemblyCatalogConstructorTests.Constructor_LockedFileAsCodeBaseArgument_ShouldThrowIOException((s) =>
Expand Down Expand Up @@ -371,7 +371,7 @@ public void Constructor3_ValueAsCodebaseArgument_ShouldSetAssemblyProperty()
});
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsFileLockingEnabled))]
public void Constructor3_LockedFileAsCodeBaseArgument_ShouldThrowFileLoad()
{
AssemblyCatalogConstructorTests.Constructor_LockedFileAsCodeBaseArgument_ShouldThrowIOException((s) =>
Expand Down Expand Up @@ -468,7 +468,7 @@ public void Constructor4_ValueAsCodebaseArgument_ShouldSetAssemblyProperty()
});
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsFileLockingEnabled))]
public void Constructor4_LockedFileAsCodeBaseArgument_ShouldThrowFileLoad()
{
AssemblyCatalogConstructorTests.Constructor_LockedFileAsCodeBaseArgument_ShouldThrowIOException((s) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void OpenFile_RaisesIsolatedStorageException()
}
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsFileLockingEnabled))]
public void OpenFile_PassesFileShare()
{
TestHelper.WipeStores();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,7 @@ public void FileInUse_CreateFromFile_FailsWithExistingReadWriteMap()
/// <summary>
/// Test exceptional behavior when trying to create a map for a non-shared file that's currently in use.
/// </summary>
[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "the emscripten implementation ignores FileShare.None")]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsFileLockingEnabled))]
public void FileInUse_CreateFromFile_FailsWithExistingNoShareFile()
{
// Already opened with a FileStream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ public sealed partial class SafeFileHandle : SafeHandleZeroOrMinusOneIsInvalid
UnixFileMode.OtherRead |
UnixFileMode.OtherWrite;

internal static bool DisableFileLocking { get; } = OperatingSystem.IsBrowser() || OperatingSystem.IsWasi()// #40065: Emscripten does not support file locking
|| AppContextConfigHelper.GetBooleanConfig("System.IO.DisableFileLocking", "DOTNET_SYSTEM_IO_DISABLEFILELOCKING", defaultValue: false);
internal static bool DisableFileLocking { get; } = OperatingSystem.IsBrowser() || OperatingSystem.IsWasi() // #40065: Emscripten does not support file locking
|| AppContextConfigHelper.GetBooleanConfig(
"System.IO.DisableFileLocking",
"DOTNET_SYSTEM_IO_DISABLEFILELOCKING",
defaultValue: (OperatingSystem.IsIOS() && !OperatingSystem.IsMacCatalyst()) || OperatingSystem.IsTvOS());

// not using bool? as it's not thread safe
private NullableBool _supportsRandomAccess /* = NullableBool.Undefined */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public class DisabledFileLockingSwitchTests
[Fact]
public static void ConfigSwitchIsHonored()
{
Assert.Equal(OperatingSystem.IsWindows(), PlatformDetection.IsFileLockingEnabled);
bool expected = OperatingSystem.IsWindows() ||
(OperatingSystem.IsIOS() && !OperatingSystem.IsMacCatalyst()) ||
OperatingSystem.IsTvOS();
Assert.Equal(expected, PlatformDetection.IsFileLockingEnabled);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<TrimmerRootDescriptor Condition="'$(TargetsAppleMobile)' == 'true' and '$(EnableAggressiveTrimming)' == 'true' and '$(UseNativeAotRuntime)' != 'true'" Include="$(MSBuildThisFileDirectory)ILLink.Descriptors.xml" />
</ItemGroup>
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.IO.DisableFileLocking" Value="true" />
<!-- The default is 'disabled' for iOS and tvOS, but these platforms technically support locking, so enable file locking here to test the non-default scenario -->
<RuntimeHostConfigurationOption Include="System.IO.DisableFileLocking" Value="false"
Condition="'$(TargetOS)' == 'ios' or '$(TargetOS)' == 'iossimulator' or '$(TargetOS)' == 'tvos' or '$(TargetOS)' == 'tvossimulator'" />
<RuntimeHostConfigurationOption Include="System.IO.DisableFileLocking" Value="true"
Condition="'$(TargetOS)' != 'ios' and '$(TargetOS)' != 'iossimulator' and '$(TargetOS)' != 'tvos' and '$(TargetOS)' != 'tvossimulator'" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Xunit;

namespace System.IO.Tests
{
public class FileLockingDefaults
{
[Fact]
[PlatformSpecific(TestPlatforms.iOS | TestPlatforms.tvOS)]
public void FileLockingDisabledByDefault()
{
Assert.False(PlatformDetection.IsFileLockingEnabled);
}

[Fact]
[PlatformSpecific(TestPlatforms.MacCatalyst)]
public void FileLockingEnabledByDefault()
{
Assert.True(PlatformDetection.IsFileLockingEnabled);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
<Compile Include="File\ReadWriteAllText.cs" />
<Compile Include="File\ReadWriteAllLines.cs" />
<Compile Include="File\SymbolicLinks.cs" />
<Compile Include="FileLockingDefaults.cs" />
<Compile Include="TestData.cs" />
<Compile Include="UnseekableFileStream.cs" />
<Compile Include="FSAssert.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ public static void GetAssemblyName()
}
}

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "File locking is not respected")]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsFileLockingEnabled))]
public static void GetAssemblyName_LockedFile()
{
using (var tempFile = new TempFile(Path.GetTempFileName(), 100))
Expand Down
Loading