2022-09-20 00:01:19 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-11-02 00:37:27 +01:00
|
|
|
"fmt"
|
2022-12-18 21:14:41 +01:00
|
|
|
"strings"
|
2022-09-20 00:01:19 +02:00
|
|
|
|
2023-08-06 21:39:41 +02:00
|
|
|
"github.com/leonelquinteros/gotext"
|
|
|
|
|
2023-03-07 22:04:06 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/db"
|
|
|
|
"github.com/Jguer/yay/v12/pkg/dep"
|
|
|
|
"github.com/Jguer/yay/v12/pkg/multierror"
|
2023-08-06 21:39:41 +02:00
|
|
|
"github.com/Jguer/yay/v12/pkg/runtime"
|
2023-03-07 22:04:06 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/settings"
|
2023-08-06 21:39:41 +02:00
|
|
|
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
2023-03-07 22:04:06 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
2023-08-06 21:39:41 +02:00
|
|
|
"github.com/Jguer/yay/v12/pkg/sync"
|
2023-03-07 22:04:06 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/upgrade"
|
2022-09-20 00:01:19 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func syncInstall(ctx context.Context,
|
2023-08-06 21:39:41 +02:00
|
|
|
run *runtime.Runtime,
|
2022-10-28 23:58:15 +02:00
|
|
|
cmdArgs *parser.Arguments,
|
|
|
|
dbExecutor db.Executor,
|
2022-09-20 00:01:19 +02:00
|
|
|
) error {
|
2023-08-06 21:39:41 +02:00
|
|
|
aurCache := run.AURClient
|
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")
|
2023-08-06 21:39:41 +02:00
|
|
|
noCheck := strings.Contains(run.Cfg.MFlags, "--nocheck")
|
2022-12-18 21:14:41 +01:00
|
|
|
if noDeps {
|
2023-08-06 21:39:41 +02:00
|
|
|
run.CmdBuilder.AddMakepkgFlag("-d")
|
2022-12-18 21:14:41 +01:00
|
|
|
}
|
2022-11-02 00:37:27 +01:00
|
|
|
|
2023-08-06 21:39:41 +02:00
|
|
|
if refreshArg && run.Cfg.Mode.AtLeastRepo() {
|
|
|
|
if errR := earlyRefresh(ctx, run.Cfg, run.CmdBuilder, cmdArgs); errR != nil {
|
2022-11-02 00:37:27 +01:00
|
|
|
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
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm,
|
2023-08-06 21:39:41 +02:00
|
|
|
noDeps, noCheck, cmdArgs.ExistsArg("needed"), run.Logger.Child("grapher"))
|
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
|
|
|
|
}
|
|
|
|
|
2023-03-05 18:31:11 +01:00
|
|
|
excluded := []string{}
|
2022-11-01 23:48:35 +01:00
|
|
|
if cmdArgs.ExistsArg("u", "sysupgrade") {
|
|
|
|
var errSysUp error
|
2022-11-15 15:44:50 +01:00
|
|
|
|
2023-02-17 20:01:26 +01:00
|
|
|
upService := upgrade.NewUpgradeService(
|
2023-08-06 21:39:41 +02:00
|
|
|
grapher, aurCache, dbExecutor, run.VCSStore,
|
|
|
|
run.Cfg, settings.NoConfirm, run.Logger.Child("upgrade"))
|
2023-02-17 20:01:26 +01:00
|
|
|
|
2023-03-08 22:30:54 +01:00
|
|
|
graph, errSysUp = upService.GraphUpgrades(ctx,
|
|
|
|
graph, cmdArgs.ExistsDouble("u", "sysupgrade"),
|
|
|
|
func(*upgrade.Upgrade) bool { return true })
|
|
|
|
if errSysUp != nil {
|
|
|
|
return errSysUp
|
|
|
|
}
|
2023-04-06 19:06:46 +02:00
|
|
|
|
|
|
|
upService.AURWarnings.Print()
|
|
|
|
|
2023-03-08 22:30:54 +01:00
|
|
|
excluded, errSysUp = upService.UserExcludeUpgrades(graph)
|
2022-11-01 23:48:35 +01:00
|
|
|
if errSysUp != nil {
|
|
|
|
return errSysUp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-06 21:39:41 +02:00
|
|
|
opService := sync.NewOperationService(ctx, dbExecutor, run)
|
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 {
|
2023-02-25 18:44:24 +01:00
|
|
|
multiErr.Add(fmt.Errorf("%w: %s %s", ErrPackagesNotFound, s, ii.Version))
|
2022-12-29 13:34:53 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
if err := multiErr.Return(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-03-05 18:31:11 +01:00
|
|
|
|
2023-08-06 21:39:41 +02:00
|
|
|
return opService.Run(ctx, run, cmdArgs, targets, excluded)
|
2023-04-11 13:51:39 +02:00
|
|
|
}
|
|
|
|
|
2023-08-06 21:39:41 +02:00
|
|
|
func earlyRefresh(ctx context.Context, cfg *settings.Configuration, cmdBuilder exe.ICmdBuilder, cmdArgs *parser.Arguments) error {
|
|
|
|
arguments := cmdArgs.Copy()
|
|
|
|
if cfg.CombinedUpgrade {
|
|
|
|
arguments.DelArg("u", "sysupgrade")
|
2023-01-23 22:43:58 +01:00
|
|
|
}
|
2023-08-06 21:39:41 +02:00
|
|
|
arguments.DelArg("s", "search")
|
|
|
|
arguments.DelArg("i", "info")
|
|
|
|
arguments.DelArg("l", "list")
|
|
|
|
arguments.ClearTargets()
|
2023-01-23 22:43:58 +01:00
|
|
|
|
2023-08-06 21:39:41 +02:00
|
|
|
return cmdBuilder.Show(cmdBuilder.BuildPacmanCmd(ctx,
|
|
|
|
arguments, cfg.Mode, settings.NoConfirm))
|
2023-01-23 22:43:58 +01:00
|
|
|
}
|