-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add File hard link API and tests #120041
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
Add File hard link API and tests #120041
Conversation
Introduce `File.CreateHardLink` and `FileSystemInfo.CreateAsHardLink` APIs to create hard links, with platform-specific implementations. Add comprehensive tests for hard link creation, behavior, and error cases for both File and FileInfo. Implements dotnet#69030
|
@dotnet-policy-service agree |
src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml
Outdated
Show resolved
Hide resolved
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 pull request adds hard link creation APIs to .NET, implementing File.CreateHardLink and FileSystemInfo.CreateAsHardLink methods with platform-specific implementations for Windows and Unix systems.
Key changes:
- Introduce public APIs for creating hard links in both File and FileSystemInfo classes
- Add platform-specific implementations using Windows Kernel32 and Unix system calls
- Implement comprehensive test coverage for hard link functionality
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Runtime/ref/System.Runtime.cs | Add public API signatures for CreateHardLink methods |
| src/libraries/System.Private.CoreLib/src/System/IO/File.cs | Implement File.CreateHardLink static method |
| src/libraries/System.Private.CoreLib/src/System/IO/FileSystemInfo.cs | Implement CreateAsHardLink instance method |
| src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Windows.cs | Windows-specific hard link implementation using Kernel32 |
| src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs | Unix-specific hard link implementation using link system call |
| src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems | Add Windows interop reference for CreateHardLink |
| src/libraries/Common/tests/System/IO/ReparsePointUtilities.cs | Add hard link test utilities and capability detection |
| src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/Base/HardLinks/BaseHardLinks.FileSystem.cs | Base test class with common hard link test scenarios |
| src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/HardLinks.cs | Tests for File.CreateHardLink API |
| src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileInfo/HardLinks.cs | Tests for FileInfo.CreateAsHardLink API |
| src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/System.IO.FileSystem.Tests.csproj | Add test files to project compilation |
src/libraries/System.Private.CoreLib/src/System/IO/FileSystemInfo.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
No functional changes.
Calling `File.WriteAllText` (creates the file if it does not exist) right after `CreateFile` might be redundant
|
Hi. May I ask the current review status of this PR? |
|
@adamsitnik Thanks for your review! All review comments have been addressed. However this ConditionalClass comment requires your attention. |
adamsitnik
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.
It looks very good, PTAL at my comments regarding test cleanup.
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarEntry.Unix.cs
Show resolved
Hide resolved
...s/System.Runtime/tests/System.IO.FileSystem.Tests/Base/HardLinks/BaseHardLinks.FileSystem.cs
Show resolved
Hide resolved
...s/System.Runtime/tests/System.IO.FileSystem.Tests/Base/HardLinks/BaseHardLinks.FileSystem.cs
Show resolved
Hide resolved
...s/System.Runtime/tests/System.IO.FileSystem.Tests/Base/HardLinks/BaseHardLinks.FileSystem.cs
Show resolved
Hide resolved
...s/System.Runtime/tests/System.IO.FileSystem.Tests/Base/HardLinks/BaseHardLinks.FileSystem.cs
Outdated
Show resolved
Hide resolved
jozkee
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.
Thanks.
adamsitnik
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.
LGTM, big thanks for your contribution @SadPencil !
Introduce
File.CreateHardLinkandFileSystemInfo.CreateAsHardLinkAPIs to create hard links, with platform-specific implementations. Add comprehensive tests for hard link creation, behavior, and error cases for both File and FileInfo.Implements and closes #69030