Skip to content

Deleting an open file is handled inconsistently  #756

Description

@drorlevywork

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testinghelpersIssues that address the testing helpersstate: ready to pickIssues that are ready for being worked ontype: bugIssues that describe misbehaving functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions