import: move bib files to correct path

Moves the files imported from `bootc-image-builder` to the appropriate
path under `pkg/` so they can be imported reverse. Also fix up the
import paths that are in these files to refer to their new locations.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
This commit is contained in:
Simon de Vlieger 2025-03-31 12:16:04 +02:00
parent 441d408aee
commit 6d0927c2f9
6 changed files with 4 additions and 4 deletions

37
pkg/util/util.go Normal file
View file

@ -0,0 +1,37 @@
package util
import (
"fmt"
"os"
"os/exec"
"strings"
"github.com/sirupsen/logrus"
)
// IsMountpoint checks if the target path is a mount point
func IsMountpoint(path string) bool {
return exec.Command("mountpoint", path).Run() == nil
}
// Synchronously invoke a command, propagating stdout and stderr
// to the current process's stdout and stderr
func RunCmdSync(cmdName string, args ...string) error {
logrus.Debugf("Running: %s %s", cmdName, strings.Join(args, " "))
cmd := exec.Command(cmdName, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("error running %s %s: %w", cmdName, strings.Join(args, " "), err)
}
return nil
}
// OutputErr takes an error from exec.Command().Output() and tries
// generate an error with stderr details
func OutputErr(err error) error {
if err, ok := err.(*exec.ExitError); ok {
return fmt.Errorf("%w, stderr:\n%s", err, err.Stderr)
}
return err
}

21
pkg/util/util_test.go Normal file
View file

@ -0,0 +1,21 @@
package util_test
import (
"fmt"
"os/exec"
"testing"
"github.com/stretchr/testify/assert"
"github.com/osbuild/image-builder-cli/pkg/util"
)
func TestOutputErrPassthrough(t *testing.T) {
err := fmt.Errorf("boom")
assert.Equal(t, util.OutputErr(err), err)
}
func TestOutputErrExecError(t *testing.T) {
_, err := exec.Command("bash", "-c", ">&2 echo some-stderr; exit 1").Output()
assert.Equal(t, "exit status 1, stderr:\nsome-stderr\n", util.OutputErr(err).Error())
}