Skip to content

Commit

Permalink
Only allow erasing disks under very certain circumstances.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Aug 6, 2021
1 parent d8ee53b commit cf39ac8
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func Run(spec *Specification, hal hal.InBand) (*event.EventEmitter, error) {
if err != nil {
return eventEmitter, errors.Wrap(err, "fetch")
}

if m != nil && m.Allocation != nil && m.Allocation.Reinstall != nil && *m.Allocation.Reinstall {
hammer.FilesystemLayout = m.Allocation.Filesystemlayout
primaryDiskWiped := false
Expand All @@ -143,9 +144,22 @@ func Run(spec *Specification, hal hal.InBand) (*event.EventEmitter, error) {
return eventEmitter, err
}

err = storage.WipeDisks()
if err != nil {
return eventEmitter, errors.Wrap(err, "wipe")
wipeDisks := false
if m == nil || m.Allocation == nil {
// the machine belongs to no one, we can safely erase disks
wipeDisks = true
}
if m != nil && m.Allocation != nil && !*m.Allocation.Succeeded {
// the allocation has not succeeded, so a user was never able to work with this machine
// we're most certainly running in a crash loop and are safe to start all over again
wipeDisks = true
}

if wipeDisks {
err = storage.WipeDisks()
if err != nil {
return eventEmitter, errors.Wrap(err, "wipe")
}
}

err = hammer.ConfigureBIOS()
Expand Down

0 comments on commit cf39ac8

Please sign in to comment.