system_update: Run system updates sooner

This commit is contained in:
Tom Wiesing 2022-11-23 15:28:15 +01:00
parent 55d5c9c529
commit dbe494751a
No known key found for this signature in database

View file

@ -3,6 +3,7 @@ package cmd
import ( import (
"fmt" "fmt"
"io" "io"
"sync"
wisski_distillery "github.com/FAU-CDI/wisski-distillery" wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/internal/cli" "github.com/FAU-CDI/wisski-distillery/internal/cli"
@ -120,10 +121,13 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
"graphdb.zip": si.Positionals.GraphdbZip, "graphdb.zip": si.Positionals.GraphdbZip,
} }
var updated = make(map[string]struct{})
var updateMutex sync.Mutex
if err := logging.LogOperation(func() error { if err := logging.LogOperation(func() error {
return status.RunErrorGroup(context.Stdout, status.Group[component.Installable, error]{ return status.RunErrorGroup(context.Stdout, status.Group[component.Installable, error]{
PrefixString: func(item component.Installable, index int) string { PrefixString: func(item component.Installable, index int) string {
return fmt.Sprintf("[install %q]: ", item.Name()) return fmt.Sprintf("[update %q]: ", item.Name())
}, },
PrefixAlign: true, PrefixAlign: true,
@ -139,7 +143,18 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
return err return err
} }
ud, ok := item.(component.Updatable)
if !ok {
return nil return nil
}
defer func() {
updateMutex.Lock()
defer updateMutex.Unlock()
updated[item.ID()] = struct{}{}
}()
return ud.Update(io)
}, },
}, dis.Installable()) }, dis.Installable())
}, context.IOStream, "Performing Stack Updates"); err != nil { }, context.IOStream, "Performing Stack Updates"); err != nil {
@ -147,10 +162,15 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
} }
if err := logging.LogOperation(func() error { if err := logging.LogOperation(func() error {
for _, component := range dis.Updatable() { for _, item := range dis.Updatable() {
name := component.Name() name := item.Name()
if err := logging.LogOperation(func() error { if err := logging.LogOperation(func() error {
return component.Update(context.IOStream) _, ok := updated[item.ID()]
if ok {
context.Println("Already updated")
return nil
}
return item.Update(context.IOStream)
}, context.IOStream, "Updating Component: %s", name); err != nil { }, context.IOStream, "Updating Component: %s", name); err != nil {
return errBootstrapComponent.WithMessageF(name, err) return errBootstrapComponent.WithMessageF(name, err)
} }