[release/6.0] SafeFileHandle.Unix: don't DeleteOnClose when lock is not successful...
authorTom Deseyn <tom.deseyn@gmail.com>
Fri, 8 Oct 2021 22:59:07 +0000 (00:59 +0200)
committerGitHub <noreply@github.com>
Fri, 8 Oct 2021 22:59:07 +0000 (16:59 -0600)
commiteb89bdeb00f5d1a64129c8ae8c9fe890dc1fc30f
tree70da59f964263c1a9f256c1fdd85550be4741f1f
parent2cc1b09f775dff8f536c831c9ea5b8403caa028e
[release/6.0] SafeFileHandle.Unix: don't DeleteOnClose when lock is not successful. (#60112)

* SafeFileHandle.Unix: don't DeleteOnClose when lock is not succesful.

In https://github.com/dotnet/runtime/pull/55153 DeleteOnClose handling
moved from FileStream to SafeFileHandle.

This unintentionally caused DeleteOnClose to be applied even when
FileShare locking fails. As on Windows, DeleteOnClose should not take
effect when sharing prevents the file from being opened.

This also swaps the order of unlink and LOCK_UN in Dispose as it was
prior to https://github.com/dotnet/runtime/pull/55153.
Either order should be fine.

* test: add ConditionalFact IsFileLockingEnabled
src/libraries/System.IO.FileSystem/tests/FileStream/SafeFileHandle.cs
src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs