From 559d86fb8e1f2399bf92dde2264474d0cddfbf45 Mon Sep 17 00:00:00 2001 From: CMGS Date: Mon, 11 May 2026 17:20:58 +0800 Subject: [PATCH] style(utils): trim RunQemuImg godoc + move subprocess marker inline The 10-line godoc duplicated the "shell out because qemu-img is authoritative" rationale that lives inline on every other subprocess site in cocoonv2 (oci/erofs.go, cloudimg/inspect.go, ch/start.go, fc/start.go, hypervisor/utils.go). Trim the godoc to its actual contract (when to use, when NOT to use) and move the shell-out justification onto the exec.CommandContext call so the pattern matches sibling files. --- utils/qemuimg.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/utils/qemuimg.go b/utils/qemuimg.go index de21da81..8b80b85c 100644 --- a/utils/qemuimg.go +++ b/utils/qemuimg.go @@ -7,20 +7,15 @@ import ( "strings" ) -// RunQemuImg shells out to qemu-img with the supplied args (e.g. -// "create", "-f", "qcow2", ...) and wraps any non-zero exit with the -// trimmed combined output. Use this for operations that have no -// meaningful stdout (create, resize, convert). For queries that need -// a clean stdout payload — e.g. `info --output=json` — call -// exec.CommandContext directly. -// -// cocoon shells out to qemu-img because there is no mature Go qcow2 -// writer that covers create/resize/convert with the same fidelity; -// upstream qemu-img is authoritative for the disk-format matrix. +// RunQemuImg shells out to qemu-img and wraps any non-zero exit with the +// trimmed combined output. Use this for operations without meaningful +// stdout (create, resize, convert); for queries that need a clean stdout +// payload (e.g. `info --output=json`), call exec.CommandContext directly. func RunQemuImg(ctx context.Context, args ...string) error { if len(args) == 0 { return fmt.Errorf("qemu-img: no args") } + // shell out because no Go qcow2 writer covers create/resize/convert at qemu-img's fidelity. out, err := exec.CommandContext(ctx, "qemu-img", args...).CombinedOutput() //nolint:gosec if err != nil { return fmt.Errorf("qemu-img %s: %s: %w", args[0], strings.TrimSpace(string(out)), err)