1
0
mirror of https://github.com/Jguer/yay synced 2024-07-03 08:51:44 +00:00
yay/sync.go

85 lines
2.0 KiB
Go
Raw Normal View History

2022-09-19 22:01:19 +00:00
package main
import (
"context"
2022-11-01 23:37:27 +00:00
"fmt"
2022-09-19 22:01:19 +00:00
"os"
"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/dep"
"github.com/Jguer/yay/v11/pkg/settings"
"github.com/Jguer/yay/v11/pkg/settings/parser"
"github.com/Jguer/yay/v11/pkg/text"
2022-11-01 23:37:27 +00:00
"github.com/leonelquinteros/gotext"
2022-09-19 22:01:19 +00:00
)
func syncInstall(ctx context.Context,
config *settings.Configuration,
2022-10-28 21:58:15 +00:00
cmdArgs *parser.Arguments,
dbExecutor db.Executor,
2022-09-19 22:01:19 +00:00
) error {
2022-10-28 21:58:15 +00:00
aurCache := config.Runtime.AURCache
2022-11-01 23:37:27 +00:00
refreshArg := cmdArgs.ExistsArg("y", "refresh")
if refreshArg && config.Runtime.Mode.AtLeastRepo() {
if errR := earlyRefresh(ctx, cmdArgs); errR != nil {
return fmt.Errorf("%s - %w", gotext.Get("error refreshing databases"), errR)
}
// we may have done -Sy, our handle now has an old
// database.
if errRefresh := dbExecutor.RefreshHandle(); errRefresh != nil {
return errRefresh
}
}
2022-10-28 21:58:15 +00:00
2022-09-19 22:01:19 +00:00
grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm, os.Stdout)
2022-11-08 00:32:21 +00:00
graph, err := grapher.GraphFromTargets(ctx, nil, cmdArgs.Targets)
2022-09-19 22:01:19 +00:00
if err != nil {
return err
}
2022-11-01 22:48:35 +00:00
if cmdArgs.ExistsArg("u", "sysupgrade") {
var errSysUp error
2022-11-08 00:32:21 +00:00
graph, _, errSysUp = sysupgradeTargetsV2(ctx, aurCache, dbExecutor, graph, cmdArgs.ExistsDouble("u", "sysupgrade"))
2022-11-01 22:48:35 +00:00
if errSysUp != nil {
return errSysUp
}
}
2022-09-19 22:01:19 +00:00
topoSorted := graph.TopoSortedLayerMap()
preparer := &Preparer{
dbExecutor: dbExecutor,
cmdBuilder: config.Runtime.CmdBuilder,
config: config,
}
installer := &Installer{dbExecutor: dbExecutor}
2022-09-19 22:44:06 +00:00
if err = preparer.Present(os.Stdout, topoSorted); err != nil {
2022-09-19 22:01:19 +00:00
return err
}
cleanFunc := preparer.ShouldCleanMakeDeps(ctx)
if cleanFunc != nil {
installer.AddPostInstallHook(cleanFunc)
}
pkgBuildDirs, err := preparer.PrepareWorkspace(ctx, topoSorted)
if err != nil {
return err
}
err = installer.Install(ctx, cmdArgs, topoSorted, pkgBuildDirs)
if err != nil {
if errHook := installer.RunPostInstallHooks(ctx); errHook != nil {
text.Errorln(errHook)
}
return err
}
return installer.RunPostInstallHooks(ctx)
}