Skip to content

Commit

Permalink
Merge pull request #800 from srl-labs/fix-del-lab
Browse files Browse the repository at this point in the history
move lab dir deletion outside of destroyLab
  • Loading branch information
hellt committed Feb 23, 2022
2 parents 242022d + 7da5a5e commit f97991b
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func destroyFn(_ *cobra.Command, _ []string) error {
topos[cont.Labels["clab-topo-file"]] = struct{}{}
}
}

log.Debugf("We got the following topos struct for destroy: %+v", topos)
for topo := range topos {
opts := append(opts,
Expand All @@ -114,10 +115,19 @@ func destroyFn(_ *cobra.Command, _ []string) error {
log.Errorf("Error occurred during the %s lab deletion %v", clab.Config.Name, err)
errs = append(errs, err)
}

if cleanup {
err = os.RemoveAll(clab.Dir.Lab)
if err != nil {
log.Errorf("error deleting lab directory: %v", err)
}
}
}

if len(errs) != 0 {
return fmt.Errorf("error(s) occurred during the deletion. Check log messages")
}

return nil
}

Expand All @@ -129,15 +139,6 @@ func destroyLab(ctx context.Context, c *clab.CLab) (err error) {
return err
}

var labDir string
if cleanup {
labDir = c.Dir.Lab
err = os.RemoveAll(labDir)
if err != nil {
log.Errorf("error deleting lab directory: %v", err)
}
}

if len(containers) == 0 {
return nil
}
Expand Down

0 comments on commit f97991b

Please sign in to comment.