Skip to content

Commit

Permalink
🐛 Fixup finalizer detection
Browse files Browse the repository at this point in the history
This caused finalizers to run also for already-installed packages
  • Loading branch information
mudler committed Jun 7, 2022
1 parent 4cb21a3 commit cfbd8bf
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions pkg/installer/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,27 @@ func NewLuetFinalizerFromYaml(data []byte) (*LuetFinalizer, error) {

func OrderFinalizers(allRepos types.PackageDatabase, toInstall map[string]ArtifactMatch, solution types.PackagesAssertions) ([]*types.Package, error) {
var toFinalize []*types.Package

populate := func(ordered types.PackagesAssertions) error {
for _, ass := range ordered {
if ass.Value {
installed, ok := toInstall[ass.Package.GetFingerPrint()]
if !ok {
// It was a dep already installed in the system, so we can skip it safely
continue
}
treePackage, err := installed.Repository.GetTree().GetDatabase().FindPackage(ass.Package)
if err != nil {
return errors.Wrap(err, "Error getting package "+ass.Package.HumanReadableString())
}

toFinalize = append(toFinalize, treePackage)
return nil
}
}
return nil
}

if len(toInstall) == 1 {
for _, w := range toInstall {
if fileHelper.Exists(w.Package.Rel(tree.FinalizerFile)) {
Expand All @@ -103,21 +124,8 @@ func OrderFinalizers(allRepos types.PackageDatabase, toInstall map[string]Artifa
if err != nil {
return toFinalize, errors.Wrap(err, "While order a solution for "+w.Package.HumanReadableString())
}
ORDER:
for _, ass := range ordered {
if ass.Value {
installed, ok := toInstall[ass.Package.GetFingerPrint()]
if !ok {
// It was a dep already installed in the system, so we can skip it safely
continue ORDER
}
treePackage, err := installed.Repository.GetTree().GetDatabase().FindPackage(ass.Package)
if err != nil {
return toFinalize, errors.Wrap(err, "Error getting package "+ass.Package.HumanReadableString())
}

toFinalize = append(toFinalize, treePackage)
}
if err := populate(ordered); err != nil {
return toFinalize, err
}
}
}
Expand All @@ -127,10 +135,8 @@ func OrderFinalizers(allRepos types.PackageDatabase, toInstall map[string]Artifa
return toFinalize, err
}

for _, o := range assertions {
if o.Value {
toFinalize = append(toFinalize, o.Package)
}
if err := populate(assertions); err != nil {
return toFinalize, err
}
}

Expand Down

0 comments on commit cfbd8bf

Please sign in to comment.