cmd/pk-mount: default to mounting at /pk if it exists

And recommend /pk.

Change-Id: I5255c203e46b503a1b4c59856e085d7359d84f4f
This commit is contained in:
Brad Fitzpatrick 2018-04-25 15:28:27 -07:00
parent 2b720aa101
commit e52593865b
1 changed files with 10 additions and 5 deletions

View File

@ -93,12 +93,17 @@ func main() {
if narg > 0 {
mountPoint = flag.Arg(0)
} else {
mountPoint, err = ioutil.TempDir("", "pk-mount")
if err != nil {
log.Fatal(err)
if fi, err := os.Stat("/pk"); err == nil && fi.IsDir() {
log.Printf("no mount point given; using /pk")
mountPoint = "/pk"
} else {
mountPoint, err = ioutil.TempDir("", "pk-mount")
if err != nil {
log.Fatal(err)
}
log.Printf("no mount point given and recommended directory /pk doesn't exist; using temp directory %s", mountPoint)
defer os.Remove(mountPoint)
}
log.Printf("No mount point given. Using: %s", mountPoint)
defer os.Remove(mountPoint)
}
errorf := func(msg string, args ...interface{}) {