8000 Change error message when using New-Item to create a symlink and the item exists by jeffbi · Pull Request #3703 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 5, 2017
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 @@ -2208,7 +2208,8 @@ protected override void NewItem(
{
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
0