fix: output of talosctl logs might be corruped

The line was not copied properly, so sometimes `talosctl logs` output
was garbled as the buffer was re-used.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
This commit is contained in:
Andrey Smirnov 2023-03-29 15:51:04 +04:00
parent 02f0a4526d
commit 289b41fe4b
No known key found for this signature in database
GPG Key ID: 7B26396447AB6DFD

View File

@ -13,6 +13,7 @@ import (
"sync"
criconstants "github.com/containerd/containerd/pkg/cri/constants"
"github.com/siderolabs/gen/slices"
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
@ -134,11 +135,14 @@ func (slicer *lineSlicer) chopper(r io.Reader, hostname string) {
scanner := bufio.NewScanner(r)
for scanner.Scan() {
line := scanner.Bytes()
line = slices.Copy(line, len(line))
slicer.respCh <- &common.Data{
Metadata: &common.Metadata{
Hostname: hostname,
},
Bytes: scanner.Bytes(),
Bytes: line,
}
}
}