mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Enable creating relative symlinks on Windows with New-Item (#8783)
This commit is contained in:
@@ -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" {
|
||||
|
||||
Reference in New Issue
Block a user