mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Change error message when using New-Item to create a symlink and the item exists (#3703)
This commit is contained in:
@@ -2208,7 +2208,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
if (symLinkExists)
|
||||
{
|
||||
WriteError(new ErrorRecord(new IOException("NewItemIOError"), "NewItemIOError", ErrorCategory.ResourceExists, path));
|
||||
string message = StringUtil.Format(FileSystemProviderStrings.SymlinkItemExists, path);
|
||||
WriteError(new ErrorRecord(new IOException(message), "SymLinkExists", ErrorCategory.ResourceExists, path));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,4 +336,7 @@
|
||||
<data name="DriveMaxSizeError" xml:space="preserve">
|
||||
<value>Maximum size for drive has been exceeded: {0}.</value>
|
||||
</data>
|
||||
</root>
|
||||
<data name="SymlinkItemExists" xml:space="preserve">
|
||||
<value>Cannot create symbolic link because the path {0} already exists.</value>
|
||||
</data>
|
||||
</root>
|
||||
|
||||
@@ -344,6 +344,9 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
|
||||
$link.LinkType | Should BeExactly "SymbolicLink"
|
||||
$link.Target | Should Be $nonFile
|
||||
}
|
||||
It "New-Item emits an error when path to symbolic link already exists." {
|
||||
{ New-Item -ItemType SymbolicLink -Path $realDir -Value $symLinkToDir -ErrorAction Stop } | ShouldBeErrorId "SymLinkExists,Microsoft.PowerShell.Commands.NewItemCommand"
|
||||
}
|
||||
It "New-Item can create a symbolic link to a directory" -Skip:($IsWindows) {
|
||||
New-Item -ItemType SymbolicLink -Path $symLinkToDir -Value $realDir
|
||||
Test-Path $symLinkToDir | Should Be $true
|
||||
|
||||
Reference in New Issue
Block a user