-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Merged
+301
−17
Merged
Add File hard link API and tests #120041
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
a9685f9
Add File hard link API and tests
SadPencil 8d8b8dd
Update CompatibilitySuppressions.xml to suppress APICompat
SadPencil e2dc032
Have to include unrelated suppressions as well
SadPencil eb72e2a
Revert "Have to include unrelated suppressions as well"
SadPencil a1d1196
Revert "Update CompatibilitySuppressions.xml to suppress APICompat"
SadPencil 944df06
Correct the expected exception in the hardlink test
SadPencil aa42eb4
Add CreateHardLink to ref
SadPencil 5536a86
Address incorrect comment
SadPencil 941730d
Reorder code blocks
SadPencil 5029136
Merge branch 'main' into feat-io-hardlink
SadPencil ea28a89
Slightly update the hard link test
SadPencil 613d944
Add mount helper assert to the base hard link test class
SadPencil 1ad09a8
Merge branch 'main' into feat-io-hardlink
SadPencil c43c1c1
Apply suggestion from @jozkee
SadPencil 12ab897
Apply suggestion from @jozkee
SadPencil df34da9
Apply suggestion from @jozkee
SadPencil 8b1bdbb
Apply suggestion from @jozkee
SadPencil f374e8c
Add CreateHardLink_LinkPathAlreadyExists_Throws test
SadPencil a175919
Move CreateAsHardLink method from FileSystemInfo to FileInfo
SadPencil b70714f
Remove GetFileSystemInfo method in FileInfo_HardLinks test
SadPencil 2e39f9b
Revert "Apply suggestion from @jozkee"
SadPencil eb318f3
Sort the CreateAsHardLink method in the ref file of System.Runtime
SadPencil d6863ec
Merge branch 'main' into feat-io-hardlink
SadPencil cdd3091
Use File.CreateHardLink() in System.Formats.Tar(.Tests)
SadPencil 064f980
Apply suggestion from @adamsitnik
SadPencil 4705f9f
Apply suggestion from @adamsitnik
SadPencil 3bd8f3b
Merge branch 'main' into feat-io-hardlink
SadPencil b035c58
Remove unused includes in System.Formats.Tar(.Tests)
SadPencil eb968ac
Remove another unused include in System.Formats.Tar.Tests
SadPencil ce6145f
Remove the unwanted empty line in BaseHardLinks_FileSystem
SadPencil 1eeb5f9
Add clean up for test files in HardLinks tests
SadPencil 9c83786
Add another clean up for test files in HardLinks tests
SadPencil 7b243d6
Format BaseHardLinks.FileSystem.cs files
SadPencil 9ab3bae
Remove the conditional attribute for the child classes of BaseHardLin…
SadPencil e09869a
Remove the conditional attribute for the child classes of BaseSymboli…
SadPencil baf0ba2
Apply the same style change for the symlink
SadPencil 3736ecf
Merge branch 'main' into feat-io-hardlink
SadPencil 48cff98
Revert some attribute changes
SadPencil c14ad79
Revert the unnecessary file clean up for the hard link tests
SadPencil fc49998
Add FileNotFoundException to the XML document of hard link methods
SadPencil 6703cdd
Merge branch 'main' into feat-io-hardlink
SadPencil 051dfd0
Merge branch 'main' into feat-io-hardlink
SadPencil 56cfa93
Add test CreateHardLink_RelativePath()
SadPencil 80347bb
Merge branch 'feat-io-hardlink' of https://github.com/SadPencil/runti…
SadPencil 44c1e26
Remove incorrect XML doc for CreateAsHardLink
SadPencil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
119 changes: 119 additions & 0 deletions
119
...ystem.Runtime/tests/System.IO.FileSystem.Tests/Base/HardLinks/BaseHardLinks.FileSystem.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.IO; | ||
using Xunit; | ||
|
||
namespace System.IO.Tests | ||
{ | ||
// Contains test methods that can be used for FileInfo or File. | ||
[ConditionalClass(typeof(MountHelper), nameof(MountHelper.CanCreateHardLinks))] | ||
public abstract class BaseHardLinks_FileSystem : FileSystemTest | ||
{ | ||
public BaseHardLinks_FileSystem() | ||
{ | ||
Assert.True(MountHelper.CanCreateHardLinks); | ||
} | ||
|
||
/// <summary>Creates a new file depending on the implementing class.</summary> | ||
protected abstract void CreateFile(string path); | ||
|
||
protected abstract void AssertLinkExists(FileSystemInfo linkInfo); | ||
|
||
/// <summary>Calls the actual public API for creating a hard link.</summary> | ||
protected abstract FileSystemInfo CreateHardLink(string path, string pathToTarget); | ||
|
||
[Fact] | ||
public void CreateHardLink_NullPathToTarget() | ||
{ | ||
Assert.Throws<ArgumentNullException>(() => CreateHardLink(GetRandomFilePath(), pathToTarget: null)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("")] | ||
[InlineData("\0")] | ||
public void CreateHardLink_InvalidPathToTarget(string pathToTarget) | ||
{ | ||
Assert.Throws<ArgumentException>(() => CreateHardLink(GetRandomFilePath(), pathToTarget)); | ||
} | ||
|
||
[Fact] | ||
public void CreateHardLink_RelativePath() | ||
{ | ||
string relativePathToTarget = GetRandomFileName(); | ||
string relativePath = GetRandomFileName(); | ||
|
||
CreateFile(relativePathToTarget); | ||
CreateHardLink(relativePath, relativePathToTarget); | ||
} | ||
|
||
[Fact] | ||
public void CreateHardLink_TargetDoesNotExist_Throws() | ||
{ | ||
string linkPath = GetRandomFilePath(); | ||
string nonExistentTarget = GetRandomFilePath(); | ||
Assert.Throws<FileNotFoundException>(() => CreateHardLink(linkPath, nonExistentTarget)); | ||
} | ||
|
||
[Fact] | ||
public void CreateHardLink_LinkPathAlreadyExists_Throws() | ||
{ | ||
string targetPath = GetRandomFilePath(); | ||
string linkPath = GetRandomFilePath(); | ||
|
||
CreateFile(targetPath); | ||
CreateFile(linkPath); | ||
|
||
Assert.Throws<IOException>(() => CreateHardLink(linkPath, targetPath)); | ||
} | ||
|
||
[Fact] | ||
public void CreateHardLink_TargetExists_Succeeds() | ||
{ | ||
string targetPath = GetRandomFilePath(); | ||
string linkPath = GetRandomFilePath(); | ||
|
||
CreateFile(targetPath); | ||
|
||
FileSystemInfo linkInfo = CreateHardLink(linkPath, targetPath); | ||
AssertLinkExists(linkInfo); | ||
|
||
// Both files should have the same content | ||
Assert.Equal(File.ReadAllText(targetPath), File.ReadAllText(linkPath)); | ||
adamsitnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
SadPencil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[Fact] | ||
public void CreateHardLink_ModifyViaOneLink_VisibleViaOther() | ||
{ | ||
string targetPath = GetRandomFilePath(); | ||
string linkPath = GetRandomFilePath(); | ||
|
||
File.WriteAllText(targetPath, "original"); | ||
CreateHardLink(linkPath, targetPath); | ||
|
||
// Modify via link | ||
File.WriteAllText(linkPath, "changed"); | ||
|
||
// Read via target | ||
Assert.Equal("changed", File.ReadAllText(targetPath)); | ||
|
||
} | ||
adamsitnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[Fact] | ||
public void CreateHardLink_DeleteOneLink_FileStillAccessible() | ||
{ | ||
string targetPath = GetRandomFilePath(); | ||
string linkPath = GetRandomFilePath(); | ||
|
||
File.WriteAllText(targetPath, "data"); | ||
CreateHardLink(linkPath, targetPath); | ||
|
||
// Delete the original file | ||
File.Delete(targetPath); | ||
|
||
// The link should still exist and have the data | ||
Assert.Equal("data", File.ReadAllText(linkPath)); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.