Repository navigation
fix: prevent deleting a file that is open without FileShare.Delete on Windows - #1615
Open
Asimmirzac wants to merge 1 commit into
Open
Asimmirzac wants to merge 1 commit into
Asimmirzac wants to merge 1 commit into
Conversation
… Windows On Windows, `File.Delete`, `FileInfo.Delete` and a recursive `Directory.Delete` now throw an `IOException` when the file has an open stream that was opened without `FileShare.Delete`, as the real file system does. Unix keeps allowing the deletion. `File.Open(path, mode, access, share)` and `File.Open(path, FileStreamOptions)` now pass the requested share mode to the stream instead of always using `FileShare.Read`. Fixes TestableIO#894 Fixes TestableIO#756 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #894
Fixes #756
On Windows,
File.Delete,FileInfo.Deleteand a recursiveDirectory.Deletenow throw anIOExceptionwhen the file has an open stream that was opened withoutFileShare.Delete, like the real file system. On Linux and macOS the file can still be deleted while it is open, which matches those platforms.To make
FileShare.Deletework,File.Open(path, mode, access, share)andFile.Open(path, FileStreamOptions)now pass the requested share mode to the stream; before, it was alwaysFileShare.Read. As a result, theFile.Open(path, mode)andFile.Open(path, mode, access)overloads now apply theFileShare.Nonethey already passed, as in .NET. Opening a file withFileMode.Create/Truncatewhile another stream has it open is still decided by the share check of the new stream.Tests cover the Windows and Unix behaviour,
FileInfo.Delete, a recursive directory delete,FileShare.Delete, and the share mode passed toFile.Open. The Windows-only tests were not run locally (Linux only).This change was prepared with AI assistance (Claude Code).
🤖 Generated with Claude Code