From cf39ac859403265ef847dab738881a46f13333ce Mon Sep 17 00:00:00 2001 From: Gerrit Date: Fri, 6 Aug 2021 11:12:48 +0200 Subject: [PATCH] Only allow erasing disks under very certain circumstances. --- cmd/root.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index dfe5f6cb..2687625c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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 @@ -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()