-
Notifications
You must be signed in to change notification settings - Fork 267
Support for locked files #445
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
Conversation
|
Second commit should help with #442, if AllowedFileShare is set to None for a file, File.Delete now throws an IOException as in regular System.IO |
|
Thanks for contributing this back! I am a bit unsure about the approach of controlling the behavior solely through So my specific proposal would be to keep the property as convenience layer and additionally support locking via Other thoughts @jpreese @robkeim @tathamoddie? |
|
Hi Florian, thanks for the feedback! The only place where I expect this to require changes is in File.OpenInternal. When we open the FileStream, we already check the AllowedFileShare property to see if what we're doing is allowed. It's trivial to add a set of the current FileShare option if successful: The tricky part is if you have several file streams open, and close one of them, what should the FileShare setting on the file then be afterwards? We will have to keep track of it somehow, and find out what the expected behavior of all combinations are. Example: While not impossible to implement, I think it would add a lot of complexity to the code. I decided to keep it simple (for now) because for the purposes of a unit test, you probably want to make sure that your tested function handles externally locked files properly. I'm happy to be convinced otherwise, but I don't really see the need to verify that my tested code path has a contested file lock with itself in a unit test? |
|
Thanks for the argumentation. You're right, keeping track of the intermediate states would add quite some complexity. So let's start with this simple solution and wait for feedback. |
fgreinacher
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.
One minor nit, otherwise looks great
|
Merged, thanks for your contribution! |
Solves #226, but needs a review to see if I missed a scenario.