Skip to content

Commit

Permalink
Release v0.9.0 #minor
Browse files Browse the repository at this point in the history
  • Loading branch information
happytreees authored Mar 16, 2023
1 parent 6233d8f commit 63337c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
29 changes: 19 additions & 10 deletions driver/mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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
Expand Down

0 comments on commit 63337c5

Please sign in to comment.