Skip to content

Commit

Permalink
fix: Merge packages in db
Browse files Browse the repository at this point in the history
Co-authored-by: Christian Richter <[email protected]>
Co-authored-by: Víctor Cuadrado Juan <[email protected]>
Signed-off-by: Víctor Cuadrado Juan <[email protected]>
Signed-off-by: Christian Richter <[email protected]>
  • Loading branch information
viccuad and Christian Richter committed Jul 6, 2021
1 parent 6972c9d commit 0422022
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions internal/solver/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package solver

import (
"fmt"
"math"

pkg "github.com/rancher-sandbox/hypper/internal/package"
Expand Down Expand Up @@ -164,28 +163,28 @@ func GetPkgdDBInstance() *PkgDB {
// but making sure that unknown inthe known CurrenState and DesiredState is not changed,
// and only unknown info is getting filled.
func MergePkgs(old pkg.Pkg, new pkg.Pkg) (result *pkg.Pkg) {
result = &new
result = &old

// Merge CurrentState and DesiredState
// E.g:
// PACKAGE CurrentState DesiredState
// old (coming from release) installed unknown
// new (coming from tomodify) unknown removed
// result installed removed
if result.CurrentState == pkg.Unknown {
result.CurrentState = old.CurrentState
if old.CurrentState == pkg.Unknown {
result.CurrentState = new.CurrentState
}
if result.DesiredState == pkg.Unknown {
result.DesiredState = old.DesiredState
if old.DesiredState == pkg.Unknown {
result.DesiredState = new.DesiredState
}

// Merge Depends and DependsOptional slices
if old.DependsRel == nil {
result.DependsRel = new.DependsRel
}
if old.DependsOptionalRel == nil {
result.DependsOptionalRel = new.DependsOptionalRel
}
// if len(old.DependsRel) == 0 {
// result.DependsRel = new.DependsRel
// }
// if len(old.DependsOptionalRel) == 0 {
// result.DependsOptionalRel = new.DependsOptionalRel
// }

return result
}
Expand Down

0 comments on commit 0422022

Please sign in to comment.