-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add internal junction support to link APIs (#57996)
* Add mount point support to link APIs. * Add junction and virtual drive tests. * Move PrintName comment outside of if else of reparseTag check. * Add Windows platform specific attribute to junction and virtual drive test classes. * Revert FILE_NAME_OPENED to FILE_NAME_NORMALIZED * Revert addition of FILE_NAME_OPENED const. * Remove unnecessary enumeration junction test. * Rename GetNewCwdPath to ChangeCurrentDirectory * Make Junction_ResolveLinkTarget a theory and test both resolveFinalTarget * Shorter name for targetPath string. Typo in comment. Fix Debug.Assert. * Clarify test comment. Change PlatformDetection for OperatingSystem check. * Cleaner unit tests for virtual drive, add indirection test * Skip virtual drive tests in Windows Nano (subst not available). Small test rename. * Simplify Junctions tests, add indirection test * Address test suggestions. * Revert MountHelper.CreateSymbolicLink changes. Unrelated, and will be refactored/removed in the future. Detect if SUBST is available in Windows machine, to bring back Nano. * Add dwReserved0 check for mount points in GetFinalLinkTarget. * Use Yoda we don't. * Fix CI issues Co-authored-by: carlossanlop <[email protected]> Co-authored-by: David Cantu <[email protected]>
- Loading branch information
1 parent
1630a67
commit f7848bc
Showing
9 changed files
with
522 additions
and
56 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
71 changes: 71 additions & 0 deletions
71
src/libraries/System.IO.FileSystem/tests/Junctions.Windows.cs
This file contains 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,71 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace System.IO.Tests | ||
{ | ||
[PlatformSpecific(TestPlatforms.Windows)] | ||
public class Junctions : BaseSymbolicLinks | ||
{ | ||
protected DirectoryInfo CreateJunction(string junctionPath, string targetPath) | ||
{ | ||
Assert.True(MountHelper.CreateJunction(junctionPath, targetPath)); | ||
DirectoryInfo junctionInfo = new(junctionPath); | ||
return junctionInfo; | ||
} | ||
|
||
[Theory] | ||
[InlineData(false)] | ||
[InlineData(true)] | ||
public void Junction_ResolveLinkTarget(bool returnFinalTarget) | ||
{ | ||
string junctionPath = GetRandomLinkPath(); | ||
string targetPath = GetRandomDirPath(); | ||
|
||
Directory.CreateDirectory(targetPath); | ||
DirectoryInfo junctionInfo = CreateJunction(junctionPath, targetPath); | ||
|
||
FileSystemInfo? targetFromDirectoryInfo = junctionInfo.ResolveLinkTarget(returnFinalTarget); | ||
FileSystemInfo? targetFromDirectory = Directory.ResolveLinkTarget(junctionPath, returnFinalTarget); | ||
|
||
Assert.True(targetFromDirectoryInfo is DirectoryInfo); | ||
Assert.True(targetFromDirectory is DirectoryInfo); | ||
|
||
Assert.Equal(targetPath, junctionInfo.LinkTarget); | ||
|
||
Assert.Equal(targetPath, targetFromDirectoryInfo.FullName); | ||
Assert.Equal(targetPath, targetFromDirectory.FullName); | ||
} | ||
|
||
[Theory] | ||
[InlineData(false)] | ||
[InlineData(true)] | ||
public void Junction_ResolveLinkTarget_WithIndirection(bool returnFinalTarget) | ||
{ | ||
string firstJunctionPath = GetRandomLinkPath(); | ||
string middleJunctionPath = GetRandomLinkPath(); | ||
string targetPath = GetRandomDirPath(); | ||
|
||
Directory.CreateDirectory(targetPath); | ||
CreateJunction(middleJunctionPath, targetPath); | ||
DirectoryInfo firstJunctionInfo = CreateJunction(firstJunctionPath, middleJunctionPath); | ||
|
||
string expectedTargetPath = returnFinalTarget ? targetPath : middleJunctionPath; | ||
|
||
FileSystemInfo? targetFromDirectoryInfo = firstJunctionInfo.ResolveLinkTarget(returnFinalTarget); | ||
FileSystemInfo? targetFromDirectory = Directory.ResolveLinkTarget(firstJunctionPath, returnFinalTarget); | ||
|
||
Assert.True(targetFromDirectoryInfo is DirectoryInfo); | ||
Assert.True(targetFromDirectory is DirectoryInfo); | ||
|
||
// Always the immediate target | ||
Assert.Equal(middleJunctionPath, firstJunctionInfo.LinkTarget); | ||
|
||
Assert.Equal(expectedTargetPath, targetFromDirectoryInfo.FullName); | ||
Assert.Equal(expectedTargetPath, targetFromDirectory.FullName); | ||
} | ||
} | ||
} |
This file contains 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 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.