-
Notifications
You must be signed in to change notification settings - Fork 266
fix: file stream sharing #1363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: file stream sharing #1363
Conversation
…ionary instead of hash set
|
Struggling to initially parse these API tests, not least because I can't seem to reproduce exactly on my machine. However, I expect the cause of failure might be because of the addition of the If this is the case, presumably this could be fixed by having Worth nothing none of the factory methods have had their arguments or argument order changed. |
@HarrisonTCodes : You change the public API surface in this PR. The API tests fail, because you didn't make this explicit in the PR. In order for the tests to succeed, you have to run the This way accidental API changes can be detected in the review. Note, that this test is explicit! |
vbreuss
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add test cases to verify the correct behavior?
|
Ah, thanks @vbreuss, sorry I missed that. I will try to run these explicit tests locally! Yes, if we are happy with the structure and changes made in this PR (which seems to be the case based on this request), I shall consider them accepted and add test cases :) |
hangy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea!
It might be useful to check if symbolic links need additional handling
src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs
Outdated
Show resolved
Hide resolved
@hangy thanks for raising this :) Maybe this is worth more discussion, and a clarification of the scope of this PR. Currently it just targets the behavior shown in the original (linked) issue, ie creation of a However, there might be appetite to improve the handling of More realistic handling of other |
src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStreamFactory.cs
Outdated
Show resolved
Hide resolved
src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs
Outdated
Show resolved
Hide resolved
tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs
Show resolved
Hide resolved
src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs
Outdated
Show resolved
Hide resolved
… accesses and shares
…and compatibility
vbreuss
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this change. I would just make some things internal to enable future refactorings without breaking changes...
src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs
Outdated
Show resolved
Hide resolved
src/TestableIO.System.IO.Abstractions.TestingHelpers/PathVerifier.cs
Outdated
Show resolved
Hide resolved
vbreuss
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the change with the FileHandles class. It looks now way cleaner and is more extensible! I have just one small issue with a method name...
| { | ||
| private readonly ConcurrentDictionary<string, ConcurrentDictionary<Guid, (FileAccess access, FileShare share)>> handles = new(); | ||
|
|
||
| public void TryAddHandle(string path, Guid guid, FileAccess access, FileShare share) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I read the method signature with Try-prefix, I expect it to return a bool. Therefore I would rename this to just AddHandle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, apologies! I have renamed the method to AddHandle in 15ed8d6

Closes #1356
This PR adds stateful handling of file streams opened with the
FileShare.Noneoption. If a file stream is attempted to be opened whilst another file stream of the same file path andFileShare.Noneis in use (that is to say, has been opened and not yet disposed), anIOExceptionwill be thrown and the creation of the second file stream will be disallowed.