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 @@ -3107,6 +3107,18 @@ protected override void ProcessRecord()
try
{
resolvedPSPaths = SessionState.Path.GetResolvedPSPathFromPSPath(path, currentContext);
if (null != LiteralPath && 0 == resolvedPSPaths.Count)
{
ItemNotFoundException pathNotFound =
new ItemNotFoundException(
path,
"PathNotFound",
SessionStateStrings.PathNotFound);
WriteError(new ErrorRecord(
pathNotFound.ErrorRecord,
pathNotFound));
continue;
}
}
finally
{
Expand Down Expand Up @@ -3253,18 +3265,23 @@ protected override void ProcessRecord()

bool shouldRecurse = Recurse;
bool treatAsFile = false;
try

// only check if path is a directory using DirectoryInfo if using FileSystemProvider
if (resolvedPath.Provider.Name.Equals(FileSystemProvider.ProviderName, StringComparison.OrdinalIgnoreCase))
{
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(providerPath);
if (di != null && (di.Attributes & System.IO.FileAttributes.ReparsePoint) != 0)
try
{
shouldRecurse = false;
treatAsFile = true;
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(providerPath);
if (di != null && (di.Attributes & System.IO.FileAttributes.ReparsePoint) != 0)
{
shouldRecurse = false;
treatAsFile = true;
}
}
catch (System.IO.FileNotFoundException)
{
// not a directory
}
}
catch (System.IO.FileNotFoundException)
{
// not a directory
}

if (!treatAsFile && !Recurse && hasChildren)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ Describe "Handling of globbing patterns" -Tags "CI" {
Copy-Item -LiteralPath $file.FullName -Destination $newPath
Test-Path -LiteralPath $newPath | Should Be $true
}

It "Remove-Item -LiteralPath should fail if it contains asterisk" {
{ Remove-Item -LiteralPath ./foo*.txt -ErrorAction Stop } | ShouldBeErrorId "PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand"
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,22 @@ Describe "Extended Registry Provider Tests" -Tags @("Feature", "RequireAdminOnWi
$result."$testPropertyName" | Should Be $testPropertyValue
}
}

Context "Validate -LiteralPath" {
It "Verify New-Item and Remove-Item work with asterisk" {
try {
$tempPath = "HKCU:\_tmp"
$testPath = "$tempPath\*\sub"
$null = New-Item -Force $testPath
$testPath | Should Exist
Remove-Item -LiteralPath $testPath
$testPath | Should Not Exist
}
finally {
Remove-Item -Recurse $tempPath -ErrorAction SilentlyContinue
}
}
}
}

} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows {
# not a .Net type so can't use BeOfType
$newItem.PSObject.TypeNames[0] | Should Be "Microsoft.WSMan.Management.WSManConfigContainerElement#ComputerLevel"
$newItem.Name | Should Be $expected
Remove-Item WSMan:\$name
Remove-Item WSMan:\$name -Recurse -Force
"WSMan:\$name" | Should Not Exist
}
finally {
Remove-Item WSMan:\$name -Force -ErrorAction SilentlyContinue
Remove-Item WSMan:\$name -Recurse -Force -ErrorAction SilentlyContinue
}
}

Expand All @@ -314,11 +314,11 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows {
$property.Value | Should Be $listenerXml.Listener.$($property.Name)
}
}
Remove-Item -Path "WSMan:\localhost\Listener\$listenerName" -Force
Remove-Item -Path "WSMan:\localhost\Listener\$listenerName" -Recurse -Force
$newListener.PSPath | Should Not Exist
}
finally {
Remove-Item -Path "WSMan:\localhost\Listener\$listenerName" -Force -ErrorAction SilentlyContinue
Remove-Item -Path "WSMan:\localhost\Listener\$listenerName" -Recurse -Force -ErrorAction SilentlyContinue
}
}

Expand All @@ -332,11 +332,11 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows {
-RunAsCredential $creds
$expectedMissingProperties = @("InitializationParameters")
Test-Plugin -Plugin $plugin -expectedMissingProperties $expectedMissingProperties
Remove-Item WSMan:\localhost\Plugin\TestPlugin2\
Remove-Item WSMan:\localhost\Plugin\TestPlugin2\ -Recurse -Force
"WSMan:\localhost\Plugin\TestPlugin2" | Should Not Exist
}
finally {
Remove-Item WSMan:\localhost\Plugin\TestPlugin2\ -Force -ErrorAction SilentlyContinue
Remove-Item WSMan:\localhost\Plugin\TestPlugin2\ -Recurse -Force -ErrorAction SilentlyContinue
}
}

Expand All @@ -363,11 +363,11 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows {
try {
$plugin = New-Item -Path WSMan:\localhost\Plugin -File $testdrive\plugin.xml -Name TestPlugin2
Test-Plugin -Plugin $plugin
Remove-Item WSMan:\localhost\Plugin\TestPlugin2\
Remove-Item WSMan:\localhost\Plugin\TestPlugin2\ -Recurse -Force
"WSMan:\localhost\Plugin\TestPlugin2\" | Should Not Exist
}
finally {
Remove-Item "WSMan:\localhost\Plugin\TestPlugin2\" -Force -ErrorAction SilentlyContinue
Remove-Item "WSMan:\localhost\Plugin\TestPlugin2\" -Recurse -Force -ErrorAction SilentlyContinue
}
}

Expand All @@ -379,11 +379,11 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows {
$properties = Get-ChildItem $resource.PSPath
($properties | Where-Object { $_.Name -eq "ResourceUri" }).Value | Should Be "http://foo/"
($properties | Where-Object { $_.Name -eq "Capability" })[0].Value | Should Be "shell"
Remove-Item $resource.PSPath
Remove-Item $resource.PSPath -Recurse -Force
$resource.PSPath | Should Not Exist
}
finally {
Remove-Item $resource.PSPath -Force -ErrorAction SilentlyContinue
Remove-Item $resource.PSPath -Recurse -Force -ErrorAction SilentlyContinue
}
}

Expand All @@ -394,7 +394,7 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows {
$parameterObj = Get-Item $parameter.PSPath
$parameterObj.Name | Should Be "foo"
$parameterObj.Value | Should Be "bar"
Remove-Item $parameter.PSPath
Remove-Item $parameter.PSPath -Force
$parameter.PSPath | Should Not Exist
}
finally {
Expand All @@ -407,16 +407,16 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows {
$sddl = "O:NSG:BAD:P(A;;GA;;;BA)"
$resource = Get-ChildItem -Path WSMan:\localhost\Plugin\TestPlugin\Resources\ | Select-Object -First 1
# remove existing security resource since the folder name is just a hash of the resource uri
Get-ChildItem "$($resource.PSPath)\Security" | Remove-Item
Get-ChildItem "$($resource.PSPath)\Security" | Remove-Item -Recurse -Force
$security = New-Item "$($resource.PSPath)\Security" -SDDL $sddl -Force
$security.PSPath | Should Exist
$securityObj = Get-Item $security.PSPath
(Get-ChildItem $securityObj.PSPath | Where-Object { $_.Name -eq 'sddl' }).Value | Should Be $sddl
Remove-Item $security.PSPath
Remove-Item $security.PSPath -Recurse -Force
$security.PSPath | Should Not Exist
}
finally {
Remove-Item $security.PSPath -Force -ErrorAction SilentlyContinue
Remove-Item $security.PSPath -Recurse -Force -ErrorAction SilentlyContinue
}
}
}
Expand Down