Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@monojenkins
Copy link
Contributor

Fixes #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);

This should now correctly line up w/ https://docs.microsoft.com/en-us/dotnet/api/system.io.fileshare?view=netframework-4.8#fields

Backport of #16247.

/cc @lambdageek @steveisok

Steve Pfister added 3 commits August 15, 2019 20:26
Switching to corefx File.Copy on unix changed the behavior 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);

The change is intended to take into account all sharing scenarios.
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.
@steveisok
Copy link
Contributor

@monojenkins build failed

@steveisok steveisok merged commit 6df5f69 into mono:2019-08 Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants