diff options
Diffstat (limited to 'doGui.go')
| -rw-r--r-- | doGui.go | 40 |
1 files changed, 35 insertions, 5 deletions
@@ -6,7 +6,6 @@ package main // An app to submit patches for the 30 GO GUI repos import ( - "fmt" "os" "strings" "time" @@ -21,7 +20,7 @@ import ( func debug() { for { time.Sleep(10 * time.Second) - log.Info("TODO: use this debug loop for something?") + // log.Info("TODO: use this debug loop for something?") } } @@ -40,17 +39,48 @@ func addDrive(devname string, displayDesc string) *Block { } func switchDrive(blk *Block) { + var inUse bool = false me.currentDev = blk - me.parted.SetText("Partition " + blk.Name) + + if isBlockDeviceInUse(blk.Name) { + log.Info("Is in use?", blk.Name) + me.parted.SetText("Partition " + blk.Name + " (in use)") + me.parted.Disable() + inUse = true + } else { + log.Info("Is probably not in use?", blk.Name) + me.parted.SetText("Partition " + blk.Name + " as gpt boot disk") + me.parted.Enable() + } log.Info("check if", me.currentDev.Name, "is in use") result, err := shell.RunVerbose([]string{"parted", me.currentDev.Name, "print"}) log.Info("result =", result.Stdout, "err =", err) out := strings.Join(result.Stdout, "\n") if err != nil { - out += fmt.Sprintf("err = %v", err) + out += log.Sprintf("err = %v", err) } me.driveInfoBox.SetText(out) + + if inUse { + // if the drive is in use already, you can just stop here + return + } + + if ok, err := hasPartitionTable(blk.Name); err != nil { + out := log.Sprintf("Error checking partition table: %s\n", err) + log.Warn(out) + me.parted.Disable() + me.driveInfoBox.SetText(out) + } else { + if !ok { + log.Printf("%s has no partition table safe for gdisk\n", blk.Name) + } else { + log.Printf("%s already has a partition table\n", blk.Name) + me.parted.SetText("Partition " + blk.Name + " (has partitions)") + me.parted.Disable() + } + } } func doGui() { @@ -95,7 +125,7 @@ func drawWindow(win *gadgets.GenericWindow) { log.Info("You must select a drive first") return } - log.Info("TODO: figure out if the drive is in use") + log.Info("If you got here, gdisk should be safe to run on", me.currentDev.Name) }) grid.NextRow() |
