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 @@ -212,10 +212,10 @@ protected override void BeginProcessing()
}
}

// If they didn't specify -Append, delete the file
// If they didn't specify -Append, empty the file
if (!_shouldAppend)
{
System.IO.File.Delete(effectiveFilePath);
System.IO.File.WriteAllText(effectiveFilePath, string.Empty);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,27 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" {
$expectedError = "CannotStartTranscription,Microsoft.PowerShell.Commands.StartTranscriptCommand"
ValidateTranscription -scriptToExecute $script -outputFilePath $null -expectedError $expectedError
}
It "Should not delete the file if it already exist" {
# Create an existing file
$transcriptFilePath = Join-Path $TestDrive ([System.IO.Path]::GetRandomFileName())
Out-File $transcriptFilePath

$FileSystemWatcher = [System.IO.FileSystemWatcher]::new((Split-Path -Parent $transcriptFilePath), (Split-Path -Leaf $transcriptFilePath))

$Job = Register-ObjectEvent -InputObject $FileSystemWatcher -EventName "Deleted" -SourceIdentifier "FileDeleted" -Action {
return "FileDeleted"
}

try {
Start-Transcript -Path $transcriptFilePath
Stop-Transcript
} finally {
Unregister-Event -SourceIdentifier "FileDeleted"
}

# Nothing should have been returned by the FileSystemWatcher
Receive-Job $job | Should -Be $null
}
It "Transcription should remain active if other runspace in the host get closed" {
try {
$ps = [powershell]::Create()
Expand Down