Change error message when using New-Item to create a symlink and the item exists (#3703)

This commit is contained in:
jeffbi
2017-05-05 10:09:34 -07:00
committed by Dongbo Wang
parent d275cee214
commit 938e13602b
3 changed files with 9 additions and 2 deletions
@@ -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