Skip to content

Commit

Permalink
Fix flashing and validating devices
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Nov 20, 2024
1 parent 9051ebd commit e975d01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
8 changes: 4 additions & 4 deletions app/dd.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ func ValidateBlockDeviceContent(iff string, of string) {
for {
n1, err1 := src.Read(buf1)
n2, err2 := dest.Read(buf2)
if err1 == io.EOF && err2 == io.EOF {
if err1 == io.EOF {
break
} else if err1 != nil && err1 != io.EOF {
} else if err1 != nil {
log.Fatalln("Encountered error while validating device!", err1)
} else if err2 != nil && err2 != io.EOF {
} else if err2 != nil {
log.Fatalln("Encountered error while validating device!", err2)
} else if n2 != n1 || err1 != nil || err2 != nil || !bytes.Equal(buf1[:n1], buf2[:n2]) {
} else if n2 < n1 || !bytes.Equal(buf1[:n1], buf2[:n1]) {
log.Fatalln("Read/write mismatch! Validation of image failed. It is unsafe to boot this device.")
}
total += n1
Expand Down
13 changes: 6 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
webview "github.com/webview/webview_go"
)

// FIXME: Validate written image.
// TODO: Future support for flashing to an internal drive?

const version = "1.0.0-alpha.2"
Expand Down Expand Up @@ -61,21 +60,21 @@ func main() {
totalPhases = "2"
}
log.Println("Phase 1/" + totalPhases + ": Unmounting disk.")
if err := app.UnmountDevice(args[1]); err != nil {
if err := app.UnmountDevice(args[2]); err != nil {
log.Println(err)
if !strings.HasSuffix(args[1], "debug.iso") {
if !strings.HasSuffix(args[2], "debug.iso") {
os.Exit(1)
}
}
log.Println("Phase 2/" + totalPhases + ": Writing ISO to disk.")
if flags.UseSystemDd {
app.RunDd(args[0], args[1])
app.RunDd(args[1], args[2])
} else {
app.FlashFileToBlockDevice(args[0], args[1])
app.FlashFileToBlockDevice(args[1], args[2])
}
if flags.DisableValidation {
if !flags.DisableValidation {
log.Println("Phase 3/" + totalPhases + ": Validating written image on disk.")
app.ValidateBlockDeviceContent(args[0], args[1])
app.ValidateBlockDeviceContent(args[1], args[2])
}
return
}
Expand Down

0 comments on commit e975d01

Please sign in to comment.