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

View File

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