[release/v7.4.2] Fix regression -Tail 0 -Wait (#20734) (#21418)

This commit is contained in:
Patrick Meinecke
2024-04-04 15:24:35 -07:00
committed by GitHub
parent 6b10aa21b8
commit c16cfe8f87
2 changed files with 12 additions and 2 deletions
@@ -87,7 +87,7 @@ namespace Microsoft.PowerShell.Commands
return;
}
if (TotalCount == 0 || Tail == 0)
if (TotalCount == 0)
{
// Don't read anything
return;
@@ -118,7 +118,7 @@ namespace Microsoft.PowerShell.Commands
// as reading forwards. So we read forwards in this case.
// If Tail is positive, we seek the right position. Or, if the seek failed
// because of an unsupported encoding, we scan forward to get the tail content.
if (Tail > 0)
if (Tail >= 0)
{
bool seekSuccess = false;
@@ -283,6 +283,16 @@ Describe "Get-Content" -Tags "CI" {
Get-Content -Path $testPath -Tail 0 | Should -BeNullOrEmpty
}
It "Should wait for content when using -Tail 0 and -Wait" {
$testValues = @(1,2,3)
$Job = Start-Job -ScriptBlock {Get-Content -Path $using:testPath -Tail 0 -Wait}
Start-Sleep -Seconds 3
Add-Content -Value $testValues -Path $testPath
Start-Sleep -Seconds 3
Compare-Object -ReferenceObject $testValues -DifferenceObject ($Job | Receive-Job) | Should -BeNullOrEmpty
$Job | Remove-Job -Force
}
It "Should throw TailAndHeadCannotCoexist when both -Tail and -TotalCount are used" {
{
Get-Content -Path $testPath -Tail 1 -TotalCount 1 -ErrorAction Stop