-
Notifications
You must be signed in to change notification settings - Fork 266
Open
Labels
state: needs discussionIssues that need further discussionIssues that need further discussiontype: bugIssues that describe misbehaving functionalityIssues that describe misbehaving functionality
Description
Describe the bug
According to C#'s filesystem API, if you open a file with FileShare.None
then it should not be possible to create other file streams to that file. If you do this using the "real" file system on Windows, it will throw an IOException
with the message: "The process cannot access the file '-local file path-' because it is being used by another process.". But using the MockFileSystem
this does not produce any error, which seems wrong.
To Reproduce
Run this code:
MockFileSystem mockFileSystem = new();
mockFileSystem.FileStream.New("SomeFile.txt", FileMode.Create, FileAccess.ReadWrite, FileShare.None); // Should cause open to fail
// mockFileSystem.File.Create("SomeFile.txt"); // Does not fail either
mockFileSystem.FileStream.New("SomeFile.txt", FileMode.Open, FileAccess.Read);
FileSystem realFileSystem = new();
realFileSystem.FileStream.New("SomeFile.txt", FileMode.Create, FileAccess.ReadWrite, FileShare.None); // Causes open to fail
// realFileSystem.File.Create("SomeFile.txt"); Also fails
realFileSystem.FileStream.New("SomeFile.txt", FileMode.Open, FileAccess.Read);
Expected behavior
It should fail when creating the "open" stream on the MockFileSystem
, but it does not.
Additional context
- TestableIO version: 22.0.16
- .NET: net8.0-windows
- Windows version: Microsoft Windows 11 Enterprise (10.0.22631 Build 22631)
Metadata
Metadata
Assignees
Labels
state: needs discussionIssues that need further discussionIssues that need further discussiontype: bugIssues that describe misbehaving functionalityIssues that describe misbehaving functionality