2022-09-20 00:01:19 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-12-29 13:34:53 +01:00
|
|
|
"errors"
|
2022-11-02 00:37:27 +01:00
|
|
|
"fmt"
|
2022-09-20 00:01:19 +02:00
|
|
|
"os"
|
2022-12-18 21:14:41 +01:00
|
|
|
"strings"
|
2022-09-20 00:01:19 +02:00
|
|
|
|
2022-11-20 03:47:23 +01:00
|
|
|
"github.com/Jguer/yay/v11/pkg/completion"
|
2022-09-20 00:01:19 +02:00
|
|
|
"github.com/Jguer/yay/v11/pkg/db"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/dep"
|
2022-11-29 13:25:36 +01:00
|
|
|
"github.com/Jguer/yay/v11/pkg/multierror"
|
2022-09-20 00:01:19 +02:00
|
|
|
"github.com/Jguer/yay/v11/pkg/settings"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/settings/parser"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/text"
|
2022-11-15 15:44:50 +01:00
|
|
|
|
2022-11-02 00:37:27 +01:00
|
|
|
"github.com/leonelquinteros/gotext"
|
2022-09-20 00:01:19 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func syncInstall(ctx context.Context,
|
|
|
|
config *settings.Configuration,
|
2022-10-28 23:58:15 +02:00
|
|
|
cmdArgs *parser.Arguments,
|
|
|
|
dbExecutor db.Executor,
|
2022-09-20 00:01:19 +02:00
|
|
|
) error {
|
2022-10-28 23:58:15 +02:00
|
|
|
aurCache := config.Runtime.AURCache
|
2022-11-02 00:37:27 +01:00
|
|
|
refreshArg := cmdArgs.ExistsArg("y", "refresh")
|
2022-12-18 21:14:41 +01:00
|
|
|
noDeps := cmdArgs.ExistsArg("d", "nodeps")
|
|
|
|
noCheck := strings.Contains(config.MFlags, "--nocheck")
|
|
|
|
if noDeps {
|
|
|
|
config.Runtime.CmdBuilder.AddMakepkgFlag("-d")
|
|
|
|
}
|
2022-11-02 00:37:27 +01:00
|
|
|
|
|
|
|
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 23:58:15 +02:00
|
|
|
|
2022-12-18 21:14:41 +01:00
|
|
|
grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm, os.Stdout, noDeps, noCheck)
|
2022-09-20 00:01:19 +02:00
|
|
|
|
2022-11-08 01:32:21 +01:00
|
|
|
graph, err := grapher.GraphFromTargets(ctx, nil, cmdArgs.Targets)
|
2022-09-20 00:01:19 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-11-01 23:48:35 +01:00
|
|
|
if cmdArgs.ExistsArg("u", "sysupgrade") {
|
|
|
|
var errSysUp error
|
2022-11-15 15:44:50 +01:00
|
|
|
|
2022-11-08 01:32:21 +01:00
|
|
|
graph, _, errSysUp = sysupgradeTargetsV2(ctx, aurCache, dbExecutor, graph, cmdArgs.ExistsDouble("u", "sysupgrade"))
|
2022-11-01 23:48:35 +01:00
|
|
|
if errSysUp != nil {
|
|
|
|
return errSysUp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-20 14:02:01 +01:00
|
|
|
opService := NewOperationService(ctx, config, dbExecutor)
|
2022-12-29 13:34:53 +01:00
|
|
|
multiErr := &multierror.MultiError{}
|
|
|
|
targets := graph.TopoSortedLayerMap(func(s string, ii *dep.InstallInfo) error {
|
|
|
|
if ii.Source == dep.Missing {
|
|
|
|
multiErr.Add(errors.New(gotext.Get("could not find %s%s", s, ii.Version)))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
if err := multiErr.Return(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return opService.Run(ctx, cmdArgs, targets)
|
2022-11-20 14:02:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type OperationService struct {
|
|
|
|
ctx context.Context
|
2022-12-16 18:23:44 +01:00
|
|
|
cfg *settings.Configuration
|
2022-11-20 14:02:01 +01:00
|
|
|
dbExecutor db.Executor
|
|
|
|
}
|
2022-09-20 00:01:19 +02:00
|
|
|
|
2022-12-16 18:23:44 +01:00
|
|
|
func NewOperationService(ctx context.Context, cfg *settings.Configuration, dbExecutor db.Executor) *OperationService {
|
2022-11-20 14:02:01 +01:00
|
|
|
return &OperationService{
|
|
|
|
ctx: ctx,
|
2022-12-16 18:23:44 +01:00
|
|
|
cfg: cfg,
|
2022-11-20 14:02:01 +01:00
|
|
|
dbExecutor: dbExecutor,
|
|
|
|
}
|
|
|
|
}
|
2022-09-20 00:01:19 +02:00
|
|
|
|
2022-11-20 14:02:01 +01:00
|
|
|
func (o *OperationService) Run(ctx context.Context,
|
|
|
|
cmdArgs *parser.Arguments,
|
|
|
|
targets []map[string]*dep.InstallInfo,
|
|
|
|
) error {
|
2022-11-29 13:25:36 +01:00
|
|
|
if len(targets) == 0 {
|
|
|
|
fmt.Fprintln(os.Stdout, "", gotext.Get("there is nothing to do"))
|
|
|
|
return nil
|
|
|
|
}
|
2022-12-29 13:34:53 +01:00
|
|
|
preparer := NewPreparer(o.dbExecutor, o.cfg.Runtime.CmdBuilder, o.cfg)
|
2022-12-16 18:23:44 +01:00
|
|
|
installer := NewInstaller(o.dbExecutor, o.cfg.Runtime.CmdBuilder, o.cfg.Runtime.VCSStore, o.cfg.Runtime.Mode)
|
2022-11-20 14:02:01 +01:00
|
|
|
|
|
|
|
pkgBuildDirs, err := preparer.Run(ctx, os.Stdout, targets)
|
2022-11-20 03:47:23 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2022-09-20 00:01:19 +02:00
|
|
|
}
|
|
|
|
|
2022-11-15 15:44:50 +01:00
|
|
|
cleanFunc := preparer.ShouldCleanMakeDeps()
|
2022-09-20 00:01:19 +02:00
|
|
|
if cleanFunc != nil {
|
|
|
|
installer.AddPostInstallHook(cleanFunc)
|
|
|
|
}
|
|
|
|
|
2022-11-20 03:47:23 +01:00
|
|
|
if cleanAURDirsFunc := preparer.ShouldCleanAURDirs(pkgBuildDirs); cleanAURDirsFunc != nil {
|
|
|
|
installer.AddPostInstallHook(cleanAURDirsFunc)
|
|
|
|
}
|
|
|
|
|
2022-12-29 13:34:53 +01:00
|
|
|
srcinfoOp := srcinfoOperator{
|
|
|
|
dbExecutor: o.dbExecutor,
|
|
|
|
cfg: o.cfg,
|
|
|
|
cmdBuilder: installer.exeCmd,
|
|
|
|
}
|
|
|
|
srcinfos, err := srcinfoOp.Run(ctx, pkgBuildDirs)
|
2022-09-20 00:01:19 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-11-20 03:47:23 +01:00
|
|
|
go func() {
|
2022-12-29 13:34:53 +01:00
|
|
|
_ = completion.Update(ctx, o.cfg.Runtime.HTTPClient, o.dbExecutor,
|
|
|
|
o.cfg.AURURL, o.cfg.Runtime.CompletionPath, o.cfg.CompletionInterval, false)
|
2022-11-20 03:47:23 +01:00
|
|
|
}()
|
2022-11-20 01:51:55 +01:00
|
|
|
|
2022-11-20 14:02:01 +01:00
|
|
|
err = installer.Install(ctx, cmdArgs, targets, pkgBuildDirs, srcinfos)
|
2022-09-20 00:01:19 +02:00
|
|
|
if err != nil {
|
|
|
|
if errHook := installer.RunPostInstallHooks(ctx); errHook != nil {
|
|
|
|
text.Errorln(errHook)
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-11-29 13:25:36 +01:00
|
|
|
var multiErr multierror.MultiError
|
|
|
|
|
|
|
|
if err := installer.CompileFailedAndIgnored(); err != nil {
|
|
|
|
multiErr.Add(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := installer.RunPostInstallHooks(ctx); err != nil {
|
|
|
|
multiErr.Add(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return multiErr.Return()
|
2022-09-20 00:01:19 +02:00
|
|
|
}
|