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 @@ -8260,7 +8260,7 @@ internal static bool IsReparsePointLikeSymlink(FileSystemInfo fileInfo)

WIN32_FIND_DATA data = default;
string fullPath = Path.TrimEndingDirectorySeparator(fileInfo.FullName);
if (fullPath.Length > MAX_PATH)
if (fullPath.Length >= MAX_PATH)
{
fullPath = PathUtils.EnsureExtendedPrefix(fullPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@ Describe "Get-ChildItem" -Tags "CI" {

BeforeAll {
# Create Test data
$max_Path = 260
$item_a = "a3fe710a-31af-4834-bc29-d0b584589838"
$item_B = "B1B691A9-B7B1-4584-AED7-5259511BEEC4"
$item_c = "c283d143-2116-4809-bf11-4f7d61613f92"
$item_D = "D39B4FD9-3E1D-4DD5-8718-22FE2C934CE3"
$item_E = "EE150FEB-0F21-4AFF-8066-AF59E925810C"
$item_F = ".F81D8514-8862-4227-B041-0529B1656A43"
$item_G = "5560A62F-74F1-4FAE-9A23-F4EBD90D2676"
$item_H = "5f05ebca-4859-11ec-81d3-0242ac130003"
$item_I = "z" * ($max_Path - $TestDrive.FullName.Length - $item_H.Length - 2)
$item_J = "32d74aae-9054-4fa7-be97-8c806d10e8b9"
$null = New-Item -Path $TestDrive -Name $item_a -ItemType "File" -Force
$null = New-Item -Path $TestDrive -Name $item_B -ItemType "File" -Force
$null = New-Item -Path $TestDrive -Name $item_c -ItemType "File" -Force
$null = New-Item -Path $TestDrive -Name $item_D -ItemType "File" -Force
$null = New-Item -Path $TestDrive -Name $item_E -ItemType "Directory" -Force
$null = New-Item -Path $TestDrive -Name $item_F -ItemType "File" -Force | ForEach-Object {$_.Attributes = "hidden"}
$null = New-Item -Path (Join-Path -Path $TestDrive -ChildPath $item_E) -Name $item_G -ItemType "File" -Force
$null = New-Item -Path $TestDrive\$item_I\$item_H -Name $item_J -ItemType "Directory" -Force

$searchRoot = Join-Path $TestDrive -ChildPath "TestPS"
$file1 = Join-Path $searchRoot -ChildPath "D1" -AdditionalChildPath "File1.txt"
Expand Down Expand Up @@ -103,16 +108,17 @@ Describe "Get-ChildItem" -Tags "CI" {
It "Should list files in sorted order" {
$files = Get-ChildItem -Path $TestDrive
$files[0].Name | Should -Be $item_E
$files[1].Name | Should -Be $item_a
$files[2].Name | Should -Be $item_B
$files[3].Name | Should -Be $item_c
$files[4].Name | Should -Be $item_D
$files[1].Name | Should -Be $item_I
$files[2].Name | Should -Be $item_a
$files[3].Name | Should -Be $item_B
$files[4].Name | Should -Be $item_c
$files[5].Name | Should -Be $item_D
}

It "Should list hidden files as well when 'Force' parameter is used" {
$files = Get-ChildItem -Path $TestDrive -Force
$files | Should -Not -BeNullOrEmpty
$files.Count | Should -Be 6
$files.Count | Should -Be 7
$files.Name.Contains($item_F) | Should -BeTrue
}

Expand All @@ -130,22 +136,22 @@ Describe "Get-ChildItem" -Tags "CI" {
}

It "Should list items in current directory only with depth set to 0" {
(Get-ChildItem -Path $TestDrive -Depth 0).Count | Should -Be 5
(Get-ChildItem -Path $TestDrive -Depth 0 -Include *).Count | Should -Be 5
(Get-ChildItem -Path $TestDrive -Depth 0 -Exclude IntentionallyNonexistent).Count | Should -Be 5
(Get-ChildItem -Path $TestDrive -Depth 0).Count | Should -Be 6
(Get-ChildItem -Path $TestDrive -Depth 0 -Include *).Count | Should -Be 6
(Get-ChildItem -Path $TestDrive -Depth 0 -Exclude IntentionallyNonexistent).Count | Should -Be 6
}

It "Should return items recursively when using 'Include' or 'Exclude' parameters" {
(Get-ChildItem -Path $TestDrive -Depth 1).Count | Should -Be 6
(Get-ChildItem -Path $TestDrive -Depth 1).Count | Should -Be 8
(Get-ChildItem -Path $TestDrive -Depth 1 -Include $item_G).Count | Should -Be 1
(Get-ChildItem -Path $TestDrive -Depth 1 -Exclude $item_a).Count | Should -Be 5
(Get-ChildItem -Path $TestDrive -Depth 1 -Exclude $item_a).Count | Should -Be 7
}

It "Should return items recursively when using 'Include' or 'Exclude' parameters with -LiteralPath" {
(Get-ChildItem -LiteralPath $TestDrive -Recurse -Exclude *).Count | Should -Be 0
(Get-ChildItem -LiteralPath $TestDrive -Recurse -Include *.dll).Count | Should -Be (Get-ChildItem $TestDrive -Recurse -Include *.dll).Count
(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
(Get-ChildItem -LiteralPath $TestDrive -Depth 1 -Exclude $item_a).Count | Should -Be 7
}

It "get-childitem path wildcard - <title>" -TestCases $PathWildCardTestCases {
Expand Down Expand Up @@ -207,6 +213,10 @@ Describe "Get-ChildItem" -Tags "CI" {
Set-Location $oldLocation
}
}

It "Should list the folder present when path length equal to MAX_PATH" {
(Get-ChildItem -Path TestDrive:\$item_I -Recurse -Force).Name.Length | Should -BeGreaterThan 0
}
}

Context 'Env: Provider' {
Expand Down