lib/config, lib/ignore: Write Windows line endings (fixes #7115) (#8052)

This commit is contained in:
Jakob Borg
2021-11-22 09:38:24 +01:00
committed by GitHub
parent 4b750b6dc3
commit 1754c93370
6 changed files with 92 additions and 3 deletions
+14
View File
@@ -9,6 +9,7 @@ package osutil
import (
"bytes"
"io"
"runtime"
)
type ReplacingWriter struct {
@@ -46,3 +47,16 @@ func (w ReplacingWriter) Write(bs []byte) (int, error) {
return written, err
}
// LineEndingsWriter returns a writer that writes platform-appropriate line
// endings. (This is a no-op on non-Windows platforms.)
func LineEndingsWriter(w io.Writer) io.Writer {
if runtime.GOOS != "windows" {
return w
}
return &ReplacingWriter{
Writer: w,
From: '\n',
To: []byte{'\r', '\n'},
}
}