Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2434,6 +2434,13 @@ protected override void NewItem(

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,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
Expand Down