From 9e939963c14e2ec67b26c8ae4777adcf54ab068b Mon Sep 17 00:00:00 2001 From: Mateus Melchiades Date: Thu, 10 Aug 2023 10:58:18 -0300 Subject: [PATCH] Fix: Properly clean unstaged queue --- core/packages.go | 5 ----- core/system.go | 20 +++++++++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/core/packages.go b/core/packages.go index ed9cb8a1..a58070a3 100644 --- a/core/packages.go +++ b/core/packages.go @@ -395,11 +395,6 @@ func (p *PackageManager) GetFinalCmd(operation ABSystemOperation) string { if operation == APPLY { finalAddPkgs, finalRemovePkgs = p.processApplyPackages() } else { - err := p.ClearUnstagedPackages() - if err != nil { - PrintVerbose("PackageManager.GetFinalCmd:err: %s", err.Error()) - panic(err) - } finalAddPkgs, finalRemovePkgs = p.processUpgradePackages() } diff --git a/core/system.go b/core/system.go index 4aec6df9..e75d921b 100644 --- a/core/system.go +++ b/core/system.go @@ -19,6 +19,7 @@ import ( "os" "os/exec" "path/filepath" + "sort" "strings" "github.com/google/uuid" @@ -183,13 +184,9 @@ func (s *ABSystem) SyncUpperEtc(newEtc string) error { func (s *ABSystem) RunCleanUpQueue(fnName string) error { PrintVerbose("ABSystem.RunCleanUpQueue: running...") - for i := 0; i < len(queue); i++ { - for j := 0; j < len(queue)-1; j++ { - if queue[j].Priority > queue[j+1].Priority { - queue[j], queue[j+1] = queue[j+1], queue[j] - } - } - } + sort.Slice(queue, func(i, j int) bool { + return queue[i].Priority < queue[j].Priority + }) for _, f := range queue { if fnName != "" && f.Name != fnName { @@ -234,6 +231,13 @@ func (s *ABSystem) RunCleanUpQueue(fnName string) error { PrintVerbose("ABSystem.RunCleanUpQueue:err(6): %s", err) return err } + case "clearUnstagedPackages": + pkgM := NewPackageManager() + err := pkgM.ClearUnstagedPackages() + if err != nil { + PrintVerbose("ABSystem.RunCleanUpQueue:err(7): %s", err) + return err + } } } @@ -613,6 +617,8 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error { return err } + s.AddToCleanUpQueue("clearUnstagedPackages", 10) + // Stage 5: Write abimage.abr.new to future/ // ------------------------------------------------ PrintVerbose("[Stage 5] ABSystemRunOperation")