Skip to content

Commit

Permalink
add new boot.InUse() helper and use in the garbage collector
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 committed Nov 16, 2016
1 parent 0004ace commit 0876073
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions boot/kernel_os.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,28 @@ func KernelOrOsRebootRequired(s *snap.Info) bool {

return false
}

// InUse checks if the given name/revision is used in the
// boot environment
func InUse(name string, rev snap.Revision) bool {
bootloader, err := partition.FindBootloader()
if err != nil {
logger.Noticef("cannot get boot settings: %s", err)
return false
}

m, err := bootloader.GetBootVars("snap_kernel", "snap_try_kernel", "snap_core", "snap_try_core")
if err != nil {
logger.Noticef("cannot get boot vars: %s", err)
return false
}

for _, v := range m {
// FIXME: fugly code/behavior duplication
if v == fmt.Sprintf("%s_%s.snap", name, rev) {
return true
}
}

return false
}
4 changes: 4 additions & 0 deletions overlord/snapstate/snapstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"reflect"
"sort"

"github.com/snapcore/snapd/boot"
"github.com/snapcore/snapd/i18n"
"github.com/snapcore/snapd/logger"
"github.com/snapcore/snapd/overlord/auth"
Expand Down Expand Up @@ -149,6 +150,9 @@ func doInstall(s *state.State, snapst *SnapState, ss *SnapSetup) (*state.TaskSet
// normal garbage collect
for i := 0; i <= currentIndex-2; i++ {
si := seq[i]
if boot.InUse(ss.Name(), si.Revision) {
continue
}
ts := removeInactiveRevision(s, ss.Name(), si.Revision)
ts.WaitFor(prev)
tasks = append(tasks, ts.Tasks()...)
Expand Down

0 comments on commit 0876073

Please sign in to comment.