mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add specific error message that creating Junctions requires absolute path (#19409)
This commit is contained in:
@@ -2434,6 +2434,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
bool exists = false;
|
||||
|
||||
// junctions require an absolute path
|
||||
if (!Path.IsPathRooted(strTargetPath))
|
||||
{
|
||||
WriteError(new ErrorRecord(new ArgumentException(FileSystemProviderStrings.JunctionAbsolutePath), "NotAbsolutePath", ErrorCategory.InvalidArgument, strTargetPath));
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
exists = GetFileSystemInfo(strTargetPath, out isDirectory) != null;
|
||||
|
||||
@@ -345,4 +345,7 @@
|
||||
<data name="CopyingLocalBytesStatus" xml:space="preserve">
|
||||
<value>{0} of {1} ({2:0.0} MB/s)</value>
|
||||
</data>
|
||||
<data name="JunctionAbsolutePath" xml:space="preserve">
|
||||
<value>Creating a junction requires an absolute path for the target.</value>
|
||||
</data>
|
||||
</root>
|
||||
|
||||
@@ -613,6 +613,17 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
|
||||
Test-Path $junctionToDir | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'New-Item fails creating junction with relative path' -Skip:(!$IsWindows) {
|
||||
try {
|
||||
Push-Location $TestDrive
|
||||
1 > 1.txt
|
||||
{ New-Item -ItemType Junction -Path 2.txt -Target 1.txt -ErrorAction Stop } | Should -Throw -ErrorId "NotAbsolutePath,Microsoft.PowerShell.Commands.NewItemCommand"
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
||||
}
|
||||
|
||||
It 'New-Item can create hardlink with relative path' {
|
||||
try {
|
||||
Push-Location $TestDrive
|
||||
|
||||
Reference in New Issue
Block a user