Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Replace Clear-Content with Out-File #66

Closed
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
6 changes: 5 additions & 1 deletion src/Log-Rotate/classes/New-LogObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ function New-LogObject {
if ($copytruncate) {
Write-Verbose "Truncating $my_fullname"
if (!$WhatIf) {
Clear-Content $my_fullname
if ($PSVersionTable.PSVersion.Major -le 6) {
"" | Out-File $my_fullname -NoNewline -Encoding ASCII
Copy link
Member

@leojonathanoh leojonathanoh Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm why the if else? It would mean Windows Powershell (<6) will output ASCII encoding, and Powershell Core (>=6) will output UTF8, which means Windows Powershell users won't get a UTF8 encoding.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because replacing ASCII with utf8 or removing encoding, will fail in Windows Server 2019 ps 5.1 build

Copy link
Member

@leojonathanoh leojonathanoh Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which component of Windows Server 2019 are you using, that fails with utf8 files? Most modern applications, and my guess with Windows Server is that it would fully support utf8 by now.

Copy link
Author

@hche608 hche608 Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which component of Windows Server 2019 are you using, that fails with utf8 files? Most modern applications, and my guess with Windows Server is that it would fully support utf8 by now.

ci-master-pr / test-powershell-5-1-windows-2019 will fail if encoding with utf8

error build
https://github.com/theohbrothers/Log-Rotate/actions/runs/7811576564/job/21306915375?pr=65

}else {
"" | Out-File $my_fullname -NoNewline -Encoding utf8
}
}
}else {
Write-Verbose "Not truncating $my_fullname"
Expand Down
Loading