-
Notifications
You must be signed in to change notification settings - Fork 5
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
Fix: Replace Clear-Content with Out-File #66
Conversation
Ah, I see now, nice catch and information. Thank you for that finding. One little request, could you prefix the PR title with 'Fix: ' to follow conventional commits, for E.g. 'Fix: Replace Clear-Content with Out-File'. It should be good then, thank you 😄 |
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Fixed in #67 |
Seems like Clear-Content is creating a new file and replaces the old one with it, while Out-File tries to write into an existing file (so opened read handles do not effect this)
https://stackoverflow.com/questions/46724371/delete-clear-opened-text-file-which-is-used-by-another-process