Skip to content

Add File hard link API and tests - #120041

Merged
adamsitnik merged 45 commits into
dotnet:mainfrom
SadPencil:feat-io-hardlink
Oct 22, 2025
Merged

Add File hard link API and tests#120041
adamsitnik merged 45 commits into
dotnet:mainfrom
SadPencil:feat-io-hardlink

Conversation

@SadPencil

@SadPencilSadPencil commented Sep 24, 2025

Copy link
Copy Markdown
Contributor

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 and closes#69030

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 #69030
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Sep 24, 2025
@SadPencil

Copy link
Copy Markdown
ContributorAuthor

@dotnet-policy-service agree

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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
FileDescription
src/libraries/System.Runtime/ref/System.Runtime.csAdd public API signatures for CreateHardLink methods
src/libraries/System.Private.CoreLib/src/System/IO/File.csImplement File.CreateHardLink static method
src/libraries/System.Private.CoreLib/src/System/IO/FileSystemInfo.csImplement CreateAsHardLink instance method
src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Windows.csWindows-specific hard link implementation using Kernel32
src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.csUnix-specific hard link implementation using link system call
src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitemsAdd Windows interop reference for CreateHardLink
src/libraries/Common/tests/System/IO/ReparsePointUtilities.csAdd hard link test utilities and capability detection
src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/Base/HardLinks/BaseHardLinks.FileSystem.csBase test class with common hard link test scenarios
src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/HardLinks.csTests for File.CreateHardLink API
src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileInfo/HardLinks.csTests for FileInfo.CreateAsHardLink API
src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/System.IO.FileSystem.Tests.csprojAdd test files to project compilation

Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/FileSystemInfo.cs Outdated
Comment threadsrc/libraries/Common/tests/System/IO/ReparsePointUtilities.cs Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jkotas
jkotas requested review from a team and removed request for jkotasSeptember 26, 2025 14:43
@SadPencil

Copy link
Copy Markdown
ContributorAuthor

Hi. May I ask the current review status of this PR?

@SadPencil

Copy link
Copy Markdown
ContributorAuthor

@adamsitnik Thanks for your review! All review comments have been addressed. However this ConditionalClass comment requires your attention.

@adamsitnikadamsitnik left a comment

Copy link
Copy Markdown
Member

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.

Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/File.cs

@jozkeejozkee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/FileInfo.cs Outdated

@adamsitnikadamsitnik left a comment

Copy link
Copy Markdown
Member

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 !

@adamsitnik
adamsitnik merged commit 7df435d into dotnet:mainOct 22, 2025
141 checks passed
@SadPencil
SadPencil deleted the feat-io-hardlink branch October 22, 2025 12:04
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Nov 22, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.IOcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: create hardlinks

5 participants

@SadPencil@adamsitnik@jkotas@jozkee