Enable creating relative symlinks on Windows with New-Item (#8783)

This commit is contained in:
Steve Lee
2019-02-07 11:44:23 -08:00
committed by Andrew
parent 6bc6257a55
commit 26a58670c1
3 changed files with 18 additions and 3 deletions
@@ -3535,7 +3535,12 @@ namespace System.Management.Automation
throw PSTraceSource.NewInvalidOperationException(SessionStateStrings.PathNotFound, targetPath);
}
content = globbedTarget[0];
// If the original target was a relative path, we want to leave it as relative if it did not require
// globbing to resolve.
if (WildcardPattern.ContainsWildcardCharacters(targetPath))
{
content = globbedTarget[0];
}
}
NewItemPrivate(providerInstance, composedPath, type, content, context);
@@ -500,7 +500,6 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
Context "Get-ChildItem and symbolic links" {
BeforeAll {
$TestDrive = "TestDrive:"
$alphaDir = Join-Path $TestDrive "sub-alpha"
$alphaLink = Join-Path $TestDrive "link-alpha"
$alphaFile1 = Join-Path $alphaDir "AlphaFile1.txt"
@@ -671,7 +670,6 @@ Describe "Copy-Item can avoid copying an item onto itself" -Tags "CI", "RequireA
# attempt is made to copy an item onto itself.
$selfCopyKey = "SelfCopy"
$TestDrive = "TestDrive:"
$subDir = "$TestDrive/sub"
$otherSubDir = "$TestDrive/other-sub"
$fileName = "file.txt"
@@ -254,6 +254,18 @@ Describe "New-Item with links" -Tags @('CI', 'RequireAdminOnWindows') {
$symbolicLinkPath = New-Item -ItemType SymbolicLink -Path "$tmpDirectory/$folderName/" -Value "/bar/"
$symbolicLinkPath | Should -Not -BeNullOrEmpty
}
It "New-Item -ItemType SymbolicLink should be able to create a relative link" -Skip:(!$IsWindows) {
try {
Push-Location $TestDrive
$relativeFilePath = Join-Path -Path . -ChildPath "relativefile.txt"
$file = New-Item -ItemType File -Path $relativeFilePath
$link = New-Item -ItemType SymbolicLink -Path ./link -Target $relativeFilePath
$link.Target | Should -BeExactly $relativeFilePath
} finally {
Pop-Location
}
}
}
Describe "New-Item with links fails for non elevated user if developer mode not enabled on Windows." -Tags "CI" {