mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Use absolute path in FileSystemProvider.CreateDirectory (#24615)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user