Skip to content

Commit

Permalink
Fix: Only remove executed items from cleanup queue
Browse files Browse the repository at this point in the history
  • Loading branch information
matbme committed Aug 11, 2023
1 parent be04c8a commit 2e96385
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions core/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,50 +201,60 @@ func (s *ABSystem) RunCleanUpQueue(fnName string) error {
return queue[i].Priority < queue[j].Priority
})

for _, f := range queue {
itemsToRemove := []int{}
for i, f := range queue {
if fnName != "" && f.Name != fnName {
continue
}

itemsToRemove = append(itemsToRemove, i)

switch f.Name {
case "umountFuture":
PrintVerbose("ABSystem.RunCleanUpQueue: Executing umountFuture")
futurePart := f.Values[0].(ABRootPartition)
err := futurePart.Partition.Unmount()
if err != nil {
PrintVerbose("ABSystem.RunCleanUpQueue:err: %s", err)
return err
}
case "closeChroot":
PrintVerbose("ABSystem.RunCleanUpQueue: Executing closeChroot")
chroot := f.Values[0].(*Chroot)
chroot.Close() // safe to ignore, already closed
case "removeNewSystem":
PrintVerbose("ABSystem.RunCleanUpQueue: Executing removeNewSystem")
newSystem := f.Values[0].(string)
err := os.RemoveAll(newSystem)
if err != nil {
PrintVerbose("ABSystem.RunCleanUpQueue:err(3): %s", err)
return err
}
case "removeNewABImage":
PrintVerbose("ABSystem.RunCleanUpQueue: Executing removeNewABImage")
newImage := f.Values[0].(string)
err := os.RemoveAll(newImage)
if err != nil {
PrintVerbose("ABSystem.RunCleanUpQueue:err(4): %s", err)
return err
}
case "umountBoot":
PrintVerbose("ABSystem.RunCleanUpQueue: Executing umountBoot")
bootPart := f.Values[0].(Partition)
err := bootPart.Unmount()
if err != nil {
PrintVerbose("ABSystem.RunCleanUpQueue:err(5): %s", err)
return err
}
case "unlockUpgrade":
PrintVerbose("ABSystem.RunCleanUpQueue: Executing unlockUpgrade")
err := s.UnlockUpgrade()
if err != nil {
PrintVerbose("ABSystem.RunCleanUpQueue:err(6): %s", err)
return err
}
case "clearUnstagedPackages":
PrintVerbose("ABSystem.RunCleanUpQueue: Executing clearUnstagedPackages")
pkgM := NewPackageManager()
err := pkgM.ClearUnstagedPackages()
if err != nil {
Expand All @@ -254,7 +264,11 @@ func (s *ABSystem) RunCleanUpQueue(fnName string) error {
}
}

s.ResetQueue()
// Remove matched items in reverse order to avoid changing indices
for i := len(itemsToRemove) - 1; i <= 0; i-- {
removeIdx := itemsToRemove[i]
queue = append(queue[:removeIdx], queue[removeIdx+1:]...)
}

PrintVerbose("ABSystem.RunCleanUpQueue: completed")
return nil
Expand Down Expand Up @@ -634,7 +648,7 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {

// Stage 5: Write abimage.abr.new to future/
// ------------------------------------------------
PrintVerbose("[Stage 5] ABSystemRunOperation")
PrintVerbose("[Stage 5] -------- ABSystemRunOperation")

if s.UserLockRequested() {
err := errors.New("upgrade locked per user request")
Expand Down

0 comments on commit 2e96385

Please sign in to comment.