Skip to content

Commit 58963b1

Browse files
authored
Merge pull request #143 from dlorenc/err
Defer the unmount.
2 parents 6e75aa4 + 7218a59 commit 58963b1

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

xhyve/xhyve.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -594,15 +594,20 @@ func (d *Driver) publicSSHKeyPath() string {
594594
return d.GetSSHKeyPath() + ".pub"
595595
}
596596

597-
func (d *Driver) extractKernelImages() error {
597+
func (d *Driver) extractKernelImages() (err error) {
598598
log.Debugf("Mounting %s", isoFilename)
599599

600-
err := hdiutil("attach", d.ResolveStorePath(isoFilename), "-mountpoint", d.ResolveStorePath(isoMountPath))
600+
volumeRootDir := d.ResolveStorePath(isoMountPath)
601+
err = hdiutil("attach", d.ResolveStorePath(isoFilename), "-mountpoint", volumeRootDir)
601602
if err != nil {
602603
return err
603604
}
604605

605-
volumeRootDir := d.ResolveStorePath(isoMountPath)
606+
defer func() {
607+
log.Debugf("Unmounting %s", isoFilename)
608+
err = hdiutil("detach", volumeRootDir)
609+
}()
610+
606611
vmlinuz := filepath.Join(volumeRootDir, "boot", d.Vmlinuz)
607612
initrd := filepath.Join(volumeRootDir, "boot", d.Initrd)
608613

@@ -616,11 +621,6 @@ func (d *Driver) extractKernelImages() error {
616621
return err
617622
}
618623

619-
log.Debugf("Unmounting %s", isoFilename)
620-
if err := hdiutil("detach", volumeRootDir); err != nil {
621-
return err
622-
}
623-
624624
return nil
625625
}
626626

0 commit comments

Comments
 (0)