-
-
Notifications
You must be signed in to change notification settings - Fork 5
Add polyfill for File.Move(..., overwrite)
#41
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
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.
Pull Request Overview
This PR adds a polyfill implementation for the File.Move(string, string, bool) overload that was introduced in .NET Core 3.0, allowing the method to be used in earlier framework versions. The polyfill enables file moving with an overwrite parameter to control whether existing destination files should be replaced.
- Implements
File.Movewith overwrite parameter usingFile.Copyfollowed byFile.Delete - Adds conditional compilation for .NET Framework, .NET Standard, and .NET Core versions prior to 3.0
- Includes test coverage for scenarios where the destination exists and doesn't exist (both with overwrite=true)
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| PolyShim/NetCore30/File.cs | Adds polyfill implementation of File.Move with overwrite parameter using Copy+Delete pattern |
| PolyShim.Tests/NetCore30/FileTests.cs | Adds unit tests for the new File.Move overload covering overwrite scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| File.Delete(sourceFileName); | ||
| } |
Copilot
AI
Nov 16, 2025
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.
The polyfill implementation is not atomic and could leave the file in both locations if File.Delete fails after File.Copy succeeds. Consider wrapping the delete in a try-catch and handling potential failures, or document this limitation. The standard File.Move is atomic on most filesystems.
| File.Delete(sourceFileName); | |
| } | |
| // WARNING: This polyfill is not atomic. If File.Delete fails after File.Copy succeeds, | |
| // the file may exist in both locations. The standard File.Move is atomic on most filesystems. | |
| try | |
| { | |
| File.Delete(sourceFileName); | |
| } | |
| catch (IOException ex) | |
| { | |
| // Optionally, handle or log the error here. | |
| // For now, rethrow to preserve original behavior. | |
| throw; | |
| } |
| catch | ||
| { | ||
| // Ignore | ||
| } |
Copilot
AI
Nov 16, 2025
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.
Generic catch clause.
| catch | ||
| { | ||
| // Ignore | ||
| } |
Copilot
AI
Nov 16, 2025
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.
Generic catch clause.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #41 +/- ##
============================
============================
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
No description provided.