Use absolute path in FileSystemProvider.CreateDirectory (#24615)

This commit is contained in:
Tadas Medišauskas
2025-05-13 11:29:48 +05:00
committed by GitHub
parent cbafa5a7f7
commit b3bc4ff4e0
2 changed files with 15 additions and 7 deletions
@@ -2665,12 +2665,6 @@ namespace Microsoft.PowerShell.Commands
!string.IsNullOrEmpty(path),
"The caller should verify path");
// Get the parent path
string parentPath = GetParentPath(path, null);
// The directory name
string childName = GetChildName(path);
ErrorRecord error = null;
if (!Force && ItemExists(path, out error))
{
@@ -2700,7 +2694,7 @@ namespace Microsoft.PowerShell.Commands
if (ShouldProcess(resource, action))
{
var result = Directory.CreateDirectory(Path.Combine(parentPath, childName));
var result = Directory.CreateDirectory(path);
if (streamOutput)
{
@@ -1206,6 +1206,20 @@ Describe "Extended FileSystem Item/Content Cmdlet Provider Tests" -Tags "Feature
$result.Name | Should -BeExactly $testDir
}
It "Verify Directory creation when path relative to current PSDrive is empty" {
try {
$rootDir = New-Item "NewDirectory" -ItemType Directory -Force
$rootPath = $rootDir.FullName
$newPSDrive = New-PSDrive -Name "NewPSDrive" -PSProvider FileSystem -Root $rootPath
$result = New-Item -Path "NewPSDrive:\" -ItemType Directory -Force
$result.FullName.TrimEnd("/\") | Should -BeExactly $newPSDrive.Root
}
finally {
Remove-PSDrive -Name "NewPSDrive" -Force -ErrorAction SilentlyContinue
}
}
It "Verify File + Value" {
$result = New-Item -Path . -ItemType File -Name $testFile -Value "Some String"
$content = Get-Content -Path $testFile