[corlib] Fix sharing mode validation rules (#16247)
commitda2c0159e9736ebb7f6d8fbe1ebc8671e4cab7e7
authorSteve Pfister <steveisok@users.noreply.github.com>
Fri, 16 Aug 2019 11:52:22 +0000 (16 07:52 -0400)
committerGitHub <noreply@github.com>
Fri, 16 Aug 2019 11:52:22 +0000 (16 07:52 -0400)
treec1e6e8aed497639f6be35328e8801252fd9ae84f
parent4dca4f66197fa118b02593b54f79570367ab46d2
[corlib] Fix sharing mode validation rules  (#16247)

Fixes https://github.com/mono/mono/issues/16032

When we switched to corefx File.Copy on unix, the behavior changed where it opened a source and destination stream in order to pass the safe handles to Interop.Sys.CopyFile. This exposed a flaw in our sharing validation rules in MonoIO.Open, which threw an exception in this scenario:

new FileStream("source.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, 2048, FileOptions.DeleteOnClose);
new FileStream("source.txt", FileMode.Open, FileAccess.Read, FileShare.Read, 2048, FileOptions.None);

Simplified the FileShare check down to:

1. If the caller specifies FileShare.None, then it's an exclusive lock and no
   sharing is allowed.

2. If the caller specifies some other FileShare option, then FileShare.None
    cannot be specified.
mcs/class/corlib/Test/System.IO/FileStreamTest.cs
mono/metadata/w32file-unix.c
mono/metadata/w32file.h