From ef6fdc55e0277315f8becdf4a933cf4a67027adb Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 18 Mar 2021 11:09:37 +0100 Subject: pkg/host: don't include empty machine info sections --- pkg/host/machine_info.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'pkg') diff --git a/pkg/host/machine_info.go b/pkg/host/machine_info.go index 9b465e025..a804ca32a 100644 --- a/pkg/host/machine_info.go +++ b/pkg/host/machine_info.go @@ -13,15 +13,20 @@ import ( func CollectMachineInfo() ([]byte, error) { buf := new(bytes.Buffer) for _, pair := range machineInfoFuncs { + pos0 := buf.Len() fmt.Fprintf(buf, "[%s]\n", pair.name) + pos1 := buf.Len() err := pair.fn(buf) if err != nil { if !os.IsNotExist(err) { return nil, err } - fmt.Fprintf(buf, "%v\n", err) } - fmt.Fprintf(buf, "%v\n\n", strings.Repeat("-", 80)) + if buf.Len() == pos1 { + buf.Truncate(pos0) + continue + } + fmt.Fprintf(buf, "\n%v\n\n", strings.Repeat("-", 80)) } return buf.Bytes(), nil } -- cgit mrf-deployment