Skip to content
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

Deleting an open file is handled inconsistently #756

Open
drorlevywork opened this issue Sep 25, 2021 · 1 comment
Open

Deleting an open file is handled inconsistently #756

drorlevywork opened this issue Sep 25, 2021 · 1 comment
Labels
area: testinghelpers Issues that address the testing helpers state: ready to pick Issues that are ready for being worked on type: bug Issues that describe misbehaving functionality

Comments

@drorlevywork
Copy link

Describe the bug
When performing a File.OpenWrite(), followed by File.Delete() the current implementation executes this without giving any indication anything is wrong.
even if attampting to perform a filestream.Flush() operation on the file that is deleted.

To Reproduce
Steps to reproduce the behavior:

fileSystem = new MockFileSystem();
var openfile = fileSystem.File.OpenWrite("somefile.txt");
openfile.Write(new byte[] { 0  }, 0, 1);
openfile.Flush();
fileSystem.File.Delete("somefile.txt");
openfile.Write(new byte[] { 0  }, 0, 1);
openfile.Flush();

Expected behavior
From quick investigation, using the normal filesystem the results of the above would be different between windows and linux, but in any case will not match with the result that occurs here, which is that it all executes with no issue.
In windows the fileSystem.File.Delete("somefile.txt"); call would fail with an exception noting that the file cannot be deleted as it is open.
meanwhile on Linux it would appear to fail on the final openfile.Flush(); call, noting that there is no longer any stream.
The outcome of the operation should match one of these, but ideally should support both.

@drorlevywork drorlevywork added state: needs discussion Issues that need further discussion type: bug Issues that describe misbehaving functionality labels Sep 25, 2021
@fgreinacher fgreinacher added state: ready to pick Issues that are ready for being worked on and removed state: needs discussion Issues that need further discussion labels Oct 29, 2021
@fgreinacher
Copy link
Contributor

Sorry for the very late response and thanks for reporting!

While it's not our goal to mirror real file system behavior 100% I agree that your code snippet should not succeed.

TIL that on Linux files can be deleted while they are opened (https://stackoverflow.com/q/16712638).

I'd try to mirror this behavior in the mock file system, or if that's hard, make it fail during the delete operation on all OSs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: testinghelpers Issues that address the testing helpers state: ready to pick Issues that are ready for being worked on type: bug Issues that describe misbehaving functionality
Projects
None yet
Development

No branches or pull requests

2 participants