8000 Change Get-ChildItem to list the content of a link to a directory on … · PowerShell/PowerShell@3e416fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 3e416fb

Browse files
jeffbidaxian-dbw
authored andcommitted
Change Get-ChildItem to list the content of a link to a directory on Unix. (#3697)
Brings Get-ChildItem in line with ls command on Unix and with the PowerShell behavior on Windows when the link is a directory symbolic link.
1 parent 1b16f77 commit 3e416fb

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/System.Management.Automation/namespaces/FileSystemProvider.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,14 +1521,6 @@ private void GetPathItems(
15211521
if (isDirectory)
15221522
{
15231523
DirectoryInfo directory = new DirectoryInfo(path);
1524-
1525-
if (!Platform.IsWindows && Platform.NonWindowsIsSymLink(directory))
1526-
{
1527-
// For Linux, treat symlink to directories like a file
1528-
WriteItemObject(directory, path, false);
1529-
return;
1530-
}
1531-
15321524
// Enumerate the directory
15331525
Dir(directory, recurse, depth, nameOnly, returnContainers);
15341526
}

test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,32 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
367367
}
368368
}
369369

370+
Context "Get-ChildItem and symbolic links" {
371+
BeforeAll {
372+
$subDir = Join-Path $TestDrive "bar"
373+
$subLink = Join-Path $TestDrive "foo"
374+
$subFile1 = Join-Path $subDir "File1.txt"
375+
$subFile2 = Join-Path $subDir "File2.txt"
376+
377+
New-Item -ItemType Directory -Path $subDir
378+
New-Item -ItemType File -Path $subFile1
379+
New-Item -ItemType File -Path $subFile2
380+
381+
$filenamePattern = "File[12]\.txt"
382+
}
383+
AfterAll {
384+
Remove-Item -Path $subLink -Force
385+
}
386+
387+
It "Get-ChildItem gets content of linked-to directory" {
388+
New-Item -ItemType SymbolicLink -Path $subLink -Value $subDir
389+
$ci = Get-ChildItem $subLink
390+
$ci.Count | Should BeExactly 2
391+
$ci[0].Name | Should MatchExactly $filenamePattern
392+
$ci[1].Name | Should MatchExactly $filenamePattern
393+
}
394+
}
395+
370396
Context "Remove-Item and hard/symbolic links" {
371397
BeforeAll {
372398
$testCases = @(

0 commit comments

Comments
 (0)
0