From 115c664c91f939356f209e2d902252168459ba06 Mon Sep 17 00:00:00 2001 From: Jeff Bienstadt Date: Fri, 5 May 2017 00:47:33 -0700 Subject: [PATCH 1/3] Change error message when using New-Item to create a symlink and the item exists (#3700) Also changed the ErrorId to "SymLinkExists". --- .../namespaces/FileSystemProvider.cs | 3 ++- .../resources/FileSystemProviderStrings.resx | 3 +++ .../Microsoft.PowerShell.Management/FileSystem.Tests.ps1 | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index f21786a29ac..142f975cce4 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -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.ItemExists, path); + WriteError(new ErrorRecord(new IOException(message), "SymLinkExists", ErrorCategory.ResourceExists, path)); return; } } diff --git a/src/System.Management.Automation/resources/FileSystemProviderStrings.resx b/src/System.Management.Automation/resources/FileSystemProviderStrings.resx index 8432c926706..d4a55554a68 100644 --- a/src/System.Management.Automation/resources/FileSystemProviderStrings.resx +++ b/src/System.Management.Automation/resources/FileSystemProviderStrings.resx @@ -336,4 +336,7 @@ Maximum size for drive has been exceeded: {0}. + + Item '{0}' already exists. + \ No newline at end of file diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 index 0a237783e96..d5db43d9bbb 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 @@ -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 fails informatively when reversing Path and Target" { + { 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 From ad4b5f2ebd7389bc2ceeef17b58bbd87c2687601 Mon Sep 17 00:00:00 2001 From: Jeff Bienstadt Date: Fri, 5 May 2017 03:33:04 -0700 Subject: [PATCH 2/3] Made test title more clear. Added newline to end of resource file. --- .../resources/FileSystemProviderStrings.resx | 2 +- .../Microsoft.PowerShell.Management/FileSystem.Tests.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/resources/FileSystemProviderStrings.resx b/src/System.Management.Automation/resources/FileSystemProviderStrings.resx index d4a55554a68..d7b442b11d6 100644 --- a/src/System.Management.Automation/resources/FileSystemProviderStrings.resx +++ b/src/System.Management.Automation/resources/FileSystemProviderStrings.resx @@ -339,4 +339,4 @@ Item '{0}' already exists. - \ No newline at end of file + diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 index d5db43d9bbb..c94aeda3fcd 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 @@ -344,7 +344,7 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows" $link.LinkType | Should BeExactly "SymbolicLink" $link.Target | Should Be $nonFile } - It "New-Item fails informatively when reversing Path and Target" { + 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) { From 8d084895c25b318c421cb3cff69b94c26778a74f Mon Sep 17 00:00:00 2001 From: Jeff Bienstadt Date: Fri, 5 May 2017 07:19:31 -0700 Subject: [PATCH 3/3] Changes per code review. Change text of error message. --- .../namespaces/FileSystemProvider.cs | 2 +- .../resources/FileSystemProviderStrings.resx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 142f975cce4..bdfa2675c34 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -2208,7 +2208,7 @@ protected override void NewItem( { if (symLinkExists) { - string message = StringUtil.Format(FileSystemProviderStrings.ItemExists, path); + string message = StringUtil.Format(FileSystemProviderStrings.SymlinkItemExists, path); WriteError(new ErrorRecord(new IOException(message), "SymLinkExists", ErrorCategory.ResourceExists, path)); return; } diff --git a/src/System.Management.Automation/resources/FileSystemProviderStrings.resx b/src/System.Management.Automation/resources/FileSystemProviderStrings.resx index d7b442b11d6..def94134b72 100644 --- a/src/System.Management.Automation/resources/FileSystemProviderStrings.resx +++ b/src/System.Management.Automation/resources/FileSystemProviderStrings.resx @@ -336,7 +336,7 @@ Maximum size for drive has been exceeded: {0}. - - Item '{0}' already exists. + + Cannot create symbolic link because the path {0} already exists.