Skip to content

Commit

Permalink
[release/v7.4.2] Fix regression -Tail 0 -Wait (#20734) (#21418)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeeminglyScience committed Apr 4, 2024
1 parent 6b10aa2 commit c16cfe8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected override void ProcessRecord()
return;
}

if (TotalCount == 0 || Tail == 0)
if (TotalCount == 0)
{
// Don't read anything
return;
Expand Down Expand Up @@ -118,7 +118,7 @@ protected override void ProcessRecord()
// 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c16cfe8

Please sign in to comment.