diff --git a/driver/mounter.go b/driver/mounter.go index db300c97..d667a5c5 100644 --- a/driver/mounter.go +++ b/driver/mounter.go @@ -7,11 +7,17 @@ import ( "os/exec" "strconv" "strings" + "syscall" "github.com/sirupsen/logrus" "golang.org/x/sys/unix" ) +const ( + runningState = "running" + blkidExitStatusNoIdentifiers = 2 +) + type Mounter interface { Format(source, fs string) error IsFormatted(source string) (bool, error) @@ -94,19 +100,22 @@ func (m *mounter) IsFormatted(source string) (bool, error) { "format-args": blkidArgs, }).Info("isFormatted called") - out, err := exec.Command(blkidCmd, blkidArgs...).CombinedOutput() + exitCode := 0 + cmd := exec.Command(blkidCmd, blkidArgs...) + err = cmd.Run() if err != nil { - return false, fmt.Errorf("checking formatting failed for %v: %v", blkidArgs, err) - } - - // assume not formatted - if string(out) == "" { - return false, nil + exitError, ok := err.(*exec.ExitError) + if !ok { + return false, fmt.Errorf("checking formatting failed: %v cmd: %q, args: %q", err, blkidCmd, blkidArgs) + } + ws := exitError.Sys().(syscall.WaitStatus) + exitCode = ws.ExitStatus() + if exitCode == blkidExitStatusNoIdentifiers { + return false, nil + } + return false, fmt.Errorf("checking formatting failed: %v cmd: %q, args: %q", err, blkidCmd, blkidArgs) } - m.log.WithFields(logrus.Fields{ - "format-output": out, - }).Info("isFormatted end") return true, nil } diff --git a/go.mod b/go.mod index dc4a07fa..07ed6299 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/vultr/metadata v1.1.0 golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c + golang.org/x/sys v0.3.0 google.golang.org/grpc v1.52.3 ) @@ -18,7 +19,6 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-retryablehttp v0.7.1 // indirect golang.org/x/net v0.4.0 // indirect - golang.org/x/sys v0.3.0 // indirect golang.org/x/text v0.5.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 // indirect