1
0
mirror of https://github.com/byReqz/go-etcher.git synced 2024-11-25 16:14:55 +00:00

show proper size for blockdevices

This commit is contained in:
Nils 2022-01-14 23:48:30 +01:00
parent 9cb93fa170
commit 4f6b025642
Signed by: byreqz
GPG Key ID: 396A62D7D436749E

21
main.go
View File

@ -146,12 +146,19 @@ func main() {
s.Suffix = " ] Opening files" s.Suffix = " ] Opening files"
s.Start() s.Start()
image, err := os.Open(input) image, err := os.Open(input)
if err != nil { var inputsize int64
s.Stop() if statinput.Size() != 0 {
fmt.Println("\r[", color.RedString("✘"), "] Opening files ") inputsize = statinput.Size()
log.Fatal(err) } else {
inputsize, err = image.Seek(0, io.SeekEnd)
} }
target, err := os.OpenFile(device, os.O_RDWR, 0660) target, err := os.OpenFile(device, os.O_RDWR, 0660)
var targetsize int64
if statdevice.Size() != 0 {
targetsize = statdevice.Size()
} else {
targetsize, err = target.Seek(0, io.SeekEnd)
}
if err != nil { if err != nil {
s.Stop() s.Stop()
fmt.Println("\r[", color.RedString("✘"), "] Opening files ") fmt.Println("\r[", color.RedString("✘"), "] Opening files ")
@ -160,8 +167,8 @@ func main() {
s.Stop() s.Stop()
fmt.Println("\r[", color.GreenString("✓"), "] Opening files ") fmt.Println("\r[", color.GreenString("✓"), "] Opening files ")
} }
inputmb := fmt.Sprint("[", statinput.Size() / 1024 / 1024, "MB]") inputmb := fmt.Sprint("[", inputsize / 1024 / 1024, "MB]")
devicemb := fmt.Sprint("[", statdevice.Size() / 1024 / 1024, "MB]") devicemb := fmt.Sprint("[", targetsize / 1024 / 1024, "MB]")
fmt.Println("[", color.BlueString("i"), "] Input device/file: " + input, inputmb) fmt.Println("[", color.BlueString("i"), "] Input device/file: " + input, inputmb)
fmt.Println("[", color.BlueString("i"), "] Output device/file: " + device, devicemb) fmt.Println("[", color.BlueString("i"), "] Output device/file: " + device, devicemb)
if statinput.Size() > statdevice.Size() { if statinput.Size() > statdevice.Size() {
@ -175,7 +182,7 @@ func main() {
log.Fatal("aborted") log.Fatal("aborted")
} }
written, err := WriteImage(image, target, statinput.Size()) written, err := WriteImage(image, target, inputsize)
if err != nil { if err != nil {
fmt.Println("\r[", color.RedString("✘"), "] Writing image,", written, "bytes written ") fmt.Println("\r[", color.RedString("✘"), "] Writing image,", written, "bytes written ")
log.Fatal(err) log.Fatal(err)