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 @@ -3774,6 +3774,12 @@ internal void NewItem(
{
PSTraceSource.NewArgumentNullException("paths");
}
else if (path.EndsWith((":" + Path.DirectorySeparatorChar), StringComparison.Ordinal) ||
path.EndsWith((":" + Path.AltDirectorySeparatorChar), StringComparison.Ordinal))
{
// path is Windows root
resolvePath = path;
}
else
{
// To be compatible with Linux OS. Which will be either '/' or '\' depends on the OS type.
Expand Down
16 changes: 0 additions & 16 deletions src/System.Management.Automation/namespaces/LocationGlobber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2013,9 +2013,6 @@ internal string GetDriveRootRelativePathFromPSPath(
// Check to see if the path is relative or absolute
bool isPathForCurrentDrive = false;

// Check to see if the path is to the root of a drive
bool isPathForRootOfDrive = false;

if (IsAbsolutePath(path, out driveName))
{
Dbg.Diagnostics.Assert(
Expand Down Expand Up @@ -2083,12 +2080,6 @@ internal string GetDriveRootRelativePathFromPSPath(
// this is the default behavior for all windows drives, and all non-filesystem
// drives on non-windows
path = path.Substring(driveName.Length + 1);

if (String.IsNullOrEmpty(path))
{
// path was to the root of a drive such as 'c:'
isPathForRootOfDrive = true;
}
}
}
}
Expand Down Expand Up @@ -2122,20 +2113,13 @@ internal string GetDriveRootRelativePathFromPSPath(

string relativePath = String.Empty;

if (isPathForRootOfDrive)
{
relativePath = context.Drive.Root;
}
else
{
relativePath =
GenerateRelativePath(
workingDriveForPath,
path,
escapeCurrentLocation,
providerInstance,
context);
}

return relativePath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,42 @@ Describe "Get-ChildItem" -Tags "CI" {
(Get-ChildItem .).Name.Length | Should -BeGreaterThan 0
}

It "Should list the contents of the root folder using Drive:\ notation" {
(Get-ChildItem TestDrive:\).Name.Length | Should -BeGreaterThan 0
}

It "Should list the contents of the root folder using Drive:\ notation from within another folder" {
try
{
Push-Location -Path TestDrive:\$item_E
(Get-ChildItem TestDrive:\ -File).Name.Length | Should -BeExactly 4
}
finally
{
Pop-Location
}
}

It "Should list the contents of the current folder using Drive: notation when in the root" {
(Get-ChildItem TestDrive:).Name.Length | Should -BeGreaterThan 0
}

It "Should list the contents of the current folder using Drive: notation when not in the root" {
try
{
Push-Location -Path TestDrive:\$item_E
(Get-ChildItem TestDrive:).Name | Should -BeExactly $item_G
}
finally
{
Pop-Location
}
}

It "Should list the contents of the home directory" {
pushd $HOME
Push-Location $HOME
(Get-ChildItem .).Name.Length | Should -BeGreaterThan 0
popd
Pop-Location
}

It "Should have a the proper fields and be populated" {
Expand Down Expand Up @@ -101,7 +133,7 @@ Describe "Get-ChildItem" -Tags "CI" {
(Get-ChildItem -LiteralPath $TestDrive -Depth 1 -Include $item_G).Count | Should Be 1
(Get-ChildItem -LiteralPath $TestDrive -Depth 1 -Exclude $item_a).Count | Should Be 5
}

It "get-childitem path wildcard - <title>" -TestCases $PathWildCardTestCases {
param($Parameters, $ExpectedCount)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,34 @@ function Clean-State
Remove-Item $FullyQualifiedFile -Force
}

if ($FullyQualifiedFileInFolder -and (Test-Path $FullyQualifiedFileInFolder))
{
Remove-Item $FullyQualifiedFileInFolder -Force
}

if ($FullyQualifiedSubFolder -and (Test-Path $FullyQualifiedSubFolder))
{
Remove-Item $FullyQualifiedSubFolder -Force
}

if (Test-Path $FullyQualifiedFolder)
{
Remove-Item $FullyQualifiedFolder -Force
}
}

Describe "New-Item" -Tags "CI" {
$tmpDirectory = $TestDrive
$testfile = "testfile.txt"
$testfolder = "newDirectory"
$testlink = "testlink"
$FullyQualifiedFile = Join-Path -Path $tmpDirectory -ChildPath $testfile
$FullyQualifiedFolder = Join-Path -Path $tmpDirectory -ChildPath $testfolder
$FullyQualifiedLink = Join-Path -Path $tmpDirectory -ChildPath $testlink
$tmpDirectory = $TestDrive
$testfile = "testfile.txt"
$testfolder = "newDirectory"
$testsubfolder = "newSubDirectory"
$testlink = "testlink"
$FullyQualifiedFile = Join-Path -Path $tmpDirectory -ChildPath $testfile
$FullyQualifiedFolder = Join-Path -Path $tmpDirectory -ChildPath $testfolder
$FullyQualifiedLink = Join-Path -Path $tmpDirectory -ChildPath $testlink
$FullyQualifiedSubFolder = Join-Path -Path $FullyQualifiedFolder -ChildPath $testsubfolder
$FullyQualifiedFileInFolder = Join-Path -Path $FullyQualifiedFolder -ChildPath $testfile


BeforeEach {
Clean-State
Expand Down Expand Up @@ -144,6 +158,30 @@ Describe "New-Item" -Tags "CI" {
Pop-Location
}
}

It "Should create a file in the current directory when using Drive: notation" {
try {
New-Item -Name $testfolder -Path "TestDrive:\" -ItemType directory > $null
Push-Location -Path "TestDrive:\$testfolder"
New-Item -Name $testfile -Path "TestDrive:" -ItemType file > $null
$FullyQualifiedFileInFolder | Should -Exist
}
finally {
Pop-Location
}
}

It "Should create a folder in the current directory when using Drive: notation" {
try {
New-Item -Name $testfolder -Path "TestDrive:\" -ItemType directory > $null
Push-Location -Path "TestDrive:\$testfolder"
New-Item -Name $testsubfolder -Path "TestDrive:" -ItemType file > $null
$FullyQualifiedSubFolder | Should -Exist
}
finally {
Pop-Location
}
}
}

# More precisely these tests require SeCreateSymbolicLinkPrivilege.
Expand Down