mirror of
https://github.com/mudler/luet.git
synced 2025-08-19 07:47:07 +00:00
🔧 take into account of multiple installs
This commit is contained in:
parent
50b23095b2
commit
ed63236516
@ -279,19 +279,17 @@ func (l *LuetInstaller) swap(o Option, syncedRepos Repositories, toRemove pkg.Pa
|
|||||||
}
|
}
|
||||||
|
|
||||||
l.Options.Context.Info("Computed operations")
|
l.Options.Context.Info("Computed operations")
|
||||||
for _, o := range ops {
|
|
||||||
|
|
||||||
|
for _, o := range ops {
|
||||||
toUninstall := ""
|
toUninstall := ""
|
||||||
toInstall := ""
|
toInstall := ""
|
||||||
for _, u := range o.Uninstall {
|
for _, u := range o.Uninstall {
|
||||||
toUninstall += u.Package.HumanReadableString()
|
toUninstall += fmt.Sprintf(" %s", u.Package.HumanReadableString())
|
||||||
}
|
}
|
||||||
for _, u := range o.Install {
|
for _, u := range o.Install {
|
||||||
toInstall += u.Package.HumanReadableString()
|
toInstall += fmt.Sprintf(" %s", u.Package.HumanReadableString())
|
||||||
}
|
}
|
||||||
|
|
||||||
l.Options.Context.Info(fmt.Sprintf("%s -> %s", toUninstall, toInstall))
|
l.Options.Context.Info(fmt.Sprintf("%s -> %s", toUninstall, toInstall))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = l.runOps(ops, s)
|
err = l.runOps(ops, s)
|
||||||
@ -417,16 +415,19 @@ func (l *LuetInstaller) getOpsWithOptions(
|
|||||||
l.Options.Context.Debug("Computing installation order")
|
l.Options.Context.Debug("Computing installation order")
|
||||||
resOps := []installerOp{}
|
resOps := []installerOp{}
|
||||||
|
|
||||||
insertPackage := func(install pkg.Package, uninstall ...pkg.Package) {
|
insertPackage := func(install []pkg.Package, uninstall ...pkg.Package) {
|
||||||
|
if len(install) == 0 && len(uninstall) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
uOpts := []operation{}
|
uOpts := []operation{}
|
||||||
for _, u := range uninstall {
|
for _, u := range uninstall {
|
||||||
uOpts = append(uOpts, operation{Package: u, Option: uninstallOpt})
|
uOpts = append(uOpts, operation{Package: u, Option: uninstallOpt})
|
||||||
}
|
}
|
||||||
resOps = append(resOps, installerOp{
|
iOpts := []installOperation{}
|
||||||
Uninstall: uOpts,
|
for _, u := range install {
|
||||||
Install: []installOperation{{
|
iOpts = append(iOpts, installOperation{
|
||||||
operation: operation{
|
operation: operation{
|
||||||
Package: install,
|
Package: u,
|
||||||
Option: installOpt,
|
Option: installOpt,
|
||||||
},
|
},
|
||||||
Matches: installMatch,
|
Matches: installMatch,
|
||||||
@ -434,11 +435,43 @@ func (l *LuetInstaller) getOpsWithOptions(
|
|||||||
Reposiories: syncedRepos,
|
Reposiories: syncedRepos,
|
||||||
Assertions: solution,
|
Assertions: solution,
|
||||||
Database: allRepos,
|
Database: allRepos,
|
||||||
}},
|
})
|
||||||
|
}
|
||||||
|
resOps = append(resOps, installerOp{
|
||||||
|
Uninstall: uOpts,
|
||||||
|
Install: iOpts,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
removals := make(map[string]interface{})
|
removals := make(map[string]interface{})
|
||||||
|
additions := make(map[string]interface{})
|
||||||
|
|
||||||
|
remove := func(p pkg.Package) {
|
||||||
|
removals[p.GetPackageName()] = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
add := func(p pkg.Package) {
|
||||||
|
additions[p.GetPackageName()] = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
added := func(p pkg.Package) bool {
|
||||||
|
_, exists := additions[p.GetPackageName()]
|
||||||
|
return exists
|
||||||
|
}
|
||||||
|
|
||||||
|
removed := func(p pkg.Package) bool {
|
||||||
|
_, exists := removals[p.GetPackageName()]
|
||||||
|
return exists
|
||||||
|
}
|
||||||
|
|
||||||
|
findToBeInstalled := func(p pkg.Package) pkg.Package {
|
||||||
|
for _, m := range installMatch {
|
||||||
|
if m.Package.GetPackageName() == p.GetPackageName() {
|
||||||
|
return m.Package
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
fileIndex := s.FileIndex()
|
fileIndex := s.FileIndex()
|
||||||
|
|
||||||
@ -478,21 +511,39 @@ func (l *LuetInstaller) getOpsWithOptions(
|
|||||||
foundPackages[pack.HumanReadableString()] = pack
|
foundPackages[pack.HumanReadableString()] = pack
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toInstall := []pkg.Package{}
|
||||||
|
if !added(match.Package) {
|
||||||
|
toInstall = append(toInstall, match.Package)
|
||||||
|
add(match.Package)
|
||||||
|
}
|
||||||
toRemove := []pkg.Package{}
|
toRemove := []pkg.Package{}
|
||||||
for _, p := range foundPackages {
|
for _, p := range foundPackages {
|
||||||
if _, ok := removals[p.GetPackageName()]; !ok {
|
if !removed(p) {
|
||||||
toRemove = append(toRemove, p)
|
toRemove = append(toRemove, p)
|
||||||
removals[p.GetPackageName()] = nil
|
if pp := findToBeInstalled(p); pp != nil && !added(pp) {
|
||||||
|
toInstall = append(toInstall, pp)
|
||||||
|
add(pp)
|
||||||
|
}
|
||||||
|
remove(p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
insertPackage(match.Package, toRemove...)
|
// toInstall needs to have:
|
||||||
|
// equivalent of what was found in foundPackages AND
|
||||||
|
// was not already added to installation
|
||||||
|
insertPackage(toInstall, toRemove...)
|
||||||
} else if pack, err := toUninstall.Find(match.Package.GetPackageName()); err == nil {
|
} else if pack, err := toUninstall.Find(match.Package.GetPackageName()); err == nil {
|
||||||
if _, ok := removals[pack.GetPackageName()]; !ok {
|
if !removed(pack) {
|
||||||
insertPackage(match.Package, pack)
|
toInstall := []pkg.Package{}
|
||||||
removals[pack.GetPackageName()] = nil
|
if !added(match.Package) {
|
||||||
|
toInstall = append(toInstall, match.Package)
|
||||||
|
add(match.Package)
|
||||||
}
|
}
|
||||||
} else {
|
insertPackage(toInstall, pack)
|
||||||
insertPackage(match.Package)
|
remove(pack)
|
||||||
|
}
|
||||||
|
} else if !added(match.Package) {
|
||||||
|
insertPackage([]pkg.Package{match.Package})
|
||||||
|
add(match.Package)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user