Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions utils/qemuimg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading